Inheritance in Views
When you create and inherit objects in some custom or specificmodules, it is better to inherit (than to replace) from an existingview to add/modify/delete some fields and preserve the others.
Example: |
---|
<record model="ir.ui.view" id="view_partner_form"> <field name="name">res.partner.form.inherit</field> <field name="model">res.partner</field> <field name="inherit_id" ref="base.view_partner_form"/> <field name="arch" type="xml"> <notebook position="inside"> <page string="Relations"> <field name="relation_ids" colspan="4" nolabel="1"/> </page> </notebook> </field> </record>
This will add a page to the notebook ofthe
The inheritance engine will parse the existing view and search forthe root nodes of
<field name="arch" type="xml">
It will append or edit the content of this tag. If this tag hassome attributes, it will look in the parent view for a node withmatching attributes (except position).
You can use these values in the position attribute:
- inside (default): your values will be appended inside the tag
- after: add the content after the tag
- before: add the content before the tag
- replace: replace the content of the tag.
Replacing Content
<record model="ir.ui.view" id="view_partner_form1"> <field name="name">res.partner.form.inherit1</field> <field name="model">res.partner</field> <field name="inherit_id" ref="base.view_partner_form"/> <field name="arch" type="xml"> <page string="Extra Info" position="replace"> <field name="relation_ids" colspan="4" nolabel="1"/> </page> </field> </record>
Will replace the content of the Extra Info tab of the notebook withthe
The parent and the inherited views are correctly updatedwith
Deleting Content
To delete a field from a form, an empty elementwith
<record model="ir.ui.view" id="view_partner_form2"> <field name="name">res.partner.form.inherit2</field> <field name="model">res.partner</field> <field name="inherit_id" ref="base.view_partner_form"/> <field name="arch" type="xml"> <field name="lang" position="replace"/> </field> </record>
Inserting Content
To add a field into a form before the specified taguse
<record model="ir.ui.view" id="view_partner_form3"> <field name="name">res.partner.form.inherit3</field> <field name="model">res.partner</field> <field name="inherit_id" ref="base.view_partner_form"/> <field name="arch" type="xml"> <field name="lang" position="before"> <field name="relation_ids"/> </field> </field> </record>
Will add
To add a field into a form after the specified taguse
<record model="ir.ui.view" id="view_partner_form4"> <field name="name">res.partner.form.inherit4</field> <field name="model">res.partner</field> <field name="inherit_id" ref="base.view_partner_form"/> <field name="arch" type="xml"> <field name="lang" position="after"> <field name="relation_ids"/> </field> </field> </record>
Will add
Multiple Changes
To make changes in more than one location, wrap the fields in adata element.
m<record model="ir.ui.view" id="view_partner_form5"> <field name="name">res.partner.form.inherit5</field> <field name="model">res.partner</field> <field name="inherit_id" ref="base.view_partner_form"/> <field name="arch" type="xml"> <data> <field name="lang" position="replace"/> <field name="website" position="after"> <field name="lang"/> </field> </data> </field> </record>
Will delete the
XPath Element
Sometimes a view is too complicated to let you simply identify atarget field by name. For example, the field might appear in twoplaces. When that happens, you can usean
<record model="ir.ui.view" id="view_partner_form6"> <field name="name">res.partner.form.inherit6</field> <field name="model">res.partner</field> <field name="inherit_id" ref="base.view_partner_form"/> <field name="arch" type="xml"> <data> <xpath expr="//field[@name='address']/form/field[@name='email']" position="after"> <field name="age"/> </xpath> <xpath expr="//field[@name='address']/tree/field[@name='email']" position="after"> <field name="age"/> </xpath> </data> </field> </record>
Will add the