OD606 unmatched-template-locator¶
A template locates an element its parent templates do not have.
| Category | Severity | Series | Needs the index |
|---|---|---|---|
| Correctness | Error | 17.0 and later | yes |
What it reports¶
A spec of a template that inherits another, such as <xpath expr="//div[hasclass('x')]"> or
<button name="x" position="after">, whose element is not in the parent template, in that
template's own parents, or in the other templates of the bundles that extend them. Each step of
an xpath that names its element, by an attribute as in div[@t-ref='x'] or by classes as in
div[hasclass('x')], must match; a spec other than an xpath must match its first attribute. A
spec that finds the element only in a template of a module missing from depends is reported too. A
module that Odoo always installs with base, such as web, counts as in depends.
Why it matters¶
The web client applies the specs when it first renders the template, and a spec that matches
nothing throws Element '...' cannot be located in element tree, which blanks the screen that
uses it. Classes and refs of Odoo's templates change between series far more often than view
fields do, so this is the usual breakage when a module's templates are ported.
The rule only checks what it can match exactly. An xpath with | or or, a step tested with
contains() or by position, and the templates of a module whose dependencies include one that is
not indexed, such as an Enterprise module, are left alone. Only the direct children of an
inheriting template are specs, so a component's position prop is not one.
Example¶
<templates>
<t t-inherit="web.ControlPanel" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o_control_panel_nav')]" position="inside">
<button class="btn btn-secondary">Export</button>
</xpath>
</t>
</templates>
The control panel's navigation block has the class o_control_panel_navigation, so the spec
matches nothing.
<templates>
<t t-inherit="web.ControlPanel" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o_control_panel_navigation')]" position="inside">
<button class="btn btn-secondary">Export</button>
</xpath>
</t>
</templates>