OD308 xmlid-used-before-definition¶
An XML id is referenced before the file that defines it is loaded.
| Category | Severity | Series | Needs the index |
|---|---|---|---|
| Correctness | Error | all | no |
What it reports¶
A reference in a data file to one of the module's own XML ids that is defined further down the
same file, or in a file Odoo loads later. Odoo loads the files of the keys it reads in the module's
series in this order, as OD502 lists them by series: init_xml, update_xml, data,
demo_xml, then demo, each list in manifest order and each file from top to bottom. A file listed
twice counts at its first place, where a reference in it can first fail.
Why it matters¶
Odoo resolves a reference at the moment it reads it, so an id defined later does not exist yet, and a fresh install stops with "External ID not found in the system". A demo file differs: see load failures. An update of a module that is already installed passes, because the id is left over from the previous install. The mistake therefore survives every test run on an existing database and surfaces the first time someone installs the module on a new one.
The model_* and field_* ids of the module's own models are not reported, including those
OD301 counts as defined for a table outside the scan: Odoo creates them when it loads
the models, before any data file. Neither are references in base, whose bootstrap records exist
before its data files load. Ids of other modules are checked by OD301
and OD302, and files the manifest does not list are left to OD502.
Example¶
<menuitem id="menu_partner_segments"
parent="contacts.res_partner_menu_config"
action="action_partner_segments"/>
<record id="action_partner_segments" model="ir.actions.act_window">
<field name="name">Segments</field>
<field name="res_model">res.partner.category</field>
</record>
The menu names the action one record before the action exists.
<record id="action_partner_segments" model="ir.actions.act_window">
<field name="name">Segments</field>
<field name="res_model">res.partner.category</field>
</record>
<menuitem id="menu_partner_segments"
parent="contacts.res_partner_menu_config"
action="action_partner_segments"/>
When the definition is in another file, list that file before this one: earlier in the same manifest key, or under a key Odoo loads earlier. Otherwise move the reference into the defining file, below the definition.