Core DevPre-alpha
How to extend a view with xpath inherit
Goal: change another module's stored sys.view.arch by merging an xpath fragment (see inherit_id on sys.view records in module XML).
When to use
- You need an extra field or layout tweak on a
base(or third-party) form without forking the whole XML arch.
Steps
- Add a
withmodel="sys.view"in your module's XML (after the parent view exists — list this file after the module that defines the parent view independs, or run-utwice if ordering is tricky). - Set
inherit_id(parent view XML id) andarch(xpath fragment). - Add the file to
manifest.json→data(after base views, in*_inherit_views.xml). - Run
-u your_module.
Live example (contacts)
The kernel contacts addon adds customer_rank to core.partner. Add the field with inherit= first — see Model inherit — then expose it in the form:
<record id="view_core_partner_form_contacts_inherit" model="sys.view"> <field name="inherit_id" ref="contacts.view_core_partner_form"/> <field name="arch" type="xml"> <xpath expr="//field[@name='phone']" position="after"> <field name="customer_rank" string="Customer Rank"/> </xpath> </field></record>Source: sumeru/addons/contacts/views/core_partner_form_inherit_views.xml
Caveats
- The merge runs on the serialized arch; xpath expressions must match that structure.
- Errors print as view-inherit warnings during sync; fix xpath and re-run
-u.
See also
- Model inherit — add fields with
inherit=before xpath - Views, actions, and menus