2
.. i18n: Inheritance in Views
3
.. i18n: ====================
9
.. i18n: When you create and inherit objects in some custom or specific modules, it is better to inherit (than to replace) from an existing view to add/modify/delete some fields and preserve the others.
12
When you create and inherit objects in some custom or specific modules, it is better to inherit (than to replace) from an existing view to add/modify/delete some fields and preserve the others.
19
.. i18n: .. code-block:: xml
21
.. i18n: <record model="ir.ui.view" id="view_partner_form">
22
.. i18n: <field name="name">res.partner.form.inherit</field>
23
.. i18n: <field name="model">res.partner</field>
24
.. i18n: <field name="inherit_id" ref="base.view_partner_form"/>
25
.. i18n: <field name="arch" type="xml">
26
.. i18n: <notebook position="inside">
27
.. i18n: <page string="Relations">
28
.. i18n: <field name="relation_ids" colspan="4" nolabel="1"/>
37
<record model="ir.ui.view" id="view_partner_form">
38
<field name="name">res.partner.form.inherit</field>
39
<field name="model">res.partner</field>
40
<field name="inherit_id" ref="base.view_partner_form"/>
41
<field name="arch" type="xml">
42
<notebook position="inside">
43
<page string="Relations">
44
<field name="relation_ids" colspan="4" nolabel="1"/>
50
.. i18n: This will add a page to the notebook of the ``res.partner.form`` view in the
54
This will add a page to the notebook of the ``res.partner.form`` view in the
57
.. i18n: The inheritance engine will parse the existing view and search for the the root nodes of
60
The inheritance engine will parse the existing view and search for the the root nodes of
62
.. i18n: .. code-block:: xml
64
.. i18n: <field name="arch" type="xml">
69
<field name="arch" type="xml">
71
.. i18n: It will append or edit the content of this tag. If this tag has some attributes,
72
.. i18n: it will look in the parent view for a node with matching attributes (except
76
It will append or edit the content of this tag. If this tag has some attributes,
77
it will look in the parent view for a node with matching attributes (except
80
.. i18n: You can use these values in the position attribute:
83
You can use these values in the position attribute:
85
.. i18n: * inside (default): your values will be appended inside the tag
86
.. i18n: * after: add the content after the tag
87
.. i18n: * before: add the content before the tag
88
.. i18n: * replace: replace the content of the tag.
91
* inside (default): your values will be appended inside the tag
92
* after: add the content after the tag
93
* before: add the content before the tag
94
* replace: replace the content of the tag.
96
.. i18n: Replacing Content
97
.. i18n: ~~~~~~~~~~~~~~~~~
103
.. i18n: .. code-block:: xml
105
.. i18n: <record model="ir.ui.view" id="view_partner_form1">
106
.. i18n: <field name="name">res.partner.form.inherit1</field>
107
.. i18n: <field name="model">res.partner</field>
108
.. i18n: <field name="inherit_id" ref="base.view_partner_form"/>
109
.. i18n: <field name="arch" type="xml">
110
.. i18n: <page string="Extra Info" position="replace">
111
.. i18n: <field name="relation_ids" colspan="4" nolabel="1"/>
119
<record model="ir.ui.view" id="view_partner_form1">
120
<field name="name">res.partner.form.inherit1</field>
121
<field name="model">res.partner</field>
122
<field name="inherit_id" ref="base.view_partner_form"/>
123
<field name="arch" type="xml">
124
<page string="Extra Info" position="replace">
125
<field name="relation_ids" colspan="4" nolabel="1"/>
130
.. i18n: Will replace the content of the Extra Info tab of the notebook with the ``relation_ids`` field.
133
Will replace the content of the Extra Info tab of the notebook with the ``relation_ids`` field.
135
.. i18n: The parent and the inherited views are correctly updated with ``--update=all`` argument like any other views.
138
The parent and the inherited views are correctly updated with ``--update=all`` argument like any other views.
140
.. i18n: Deleting Content
141
.. i18n: ~~~~~~~~~~~~~~~~
147
.. i18n: To delete a field from a form, an empty element with ``position="replace"`` attribute is used. Example:
150
To delete a field from a form, an empty element with ``position="replace"`` attribute is used. Example:
152
.. i18n: .. code-block:: xml
154
.. i18n: <record model="ir.ui.view" id="view_partner_form2">
155
.. i18n: <field name="name">res.partner.form.inherit2</field>
156
.. i18n: <field name="model">res.partner</field>
157
.. i18n: <field name="inherit_id" ref="base.view_partner_form"/>
158
.. i18n: <field name="arch" type="xml">
159
.. i18n: <field name="lang" position="replace"/>
166
<record model="ir.ui.view" id="view_partner_form2">
167
<field name="name">res.partner.form.inherit2</field>
168
<field name="model">res.partner</field>
169
<field name="inherit_id" ref="base.view_partner_form"/>
170
<field name="arch" type="xml">
171
<field name="lang" position="replace"/>
175
.. i18n: Inserting Content
176
.. i18n: ~~~~~~~~~~~~~~~~~
182
.. i18n: To add a field into a form before the specified tag use ``position="before"`` attribute.
185
To add a field into a form before the specified tag use ``position="before"`` attribute.
187
.. i18n: .. code-block:: xml
189
.. i18n: <record model="ir.ui.view" id="view_partner_form3">
190
.. i18n: <field name="name">res.partner.form.inherit3</field>
191
.. i18n: <field name="model">res.partner</field>
192
.. i18n: <field name="inherit_id" ref="base.view_partner_form"/>
193
.. i18n: <field name="arch" type="xml">
194
.. i18n: <field name="lang" position="before">
195
.. i18n: <field name="relation_ids"/>
200
.. i18n: Will add ``relation_ids`` field before the ``lang`` field.
205
<record model="ir.ui.view" id="view_partner_form3">
206
<field name="name">res.partner.form.inherit3</field>
207
<field name="model">res.partner</field>
208
<field name="inherit_id" ref="base.view_partner_form"/>
209
<field name="arch" type="xml">
210
<field name="lang" position="before">
211
<field name="relation_ids"/>
216
Will add ``relation_ids`` field before the ``lang`` field.
218
.. i18n: To add a field into a form after the specified tag use ``position="after"`` attribute.
221
To add a field into a form after the specified tag use ``position="after"`` attribute.
223
.. i18n: .. code-block:: xml
225
.. i18n: <record model="ir.ui.view" id="view_partner_form4">
226
.. i18n: <field name="name">res.partner.form.inherit4</field>
227
.. i18n: <field name="model">res.partner</field>
228
.. i18n: <field name="inherit_id" ref="base.view_partner_form"/>
229
.. i18n: <field name="arch" type="xml">
230
.. i18n: <field name="lang" position="after">
231
.. i18n: <field name="relation_ids"/>
236
.. i18n: Will add ``relation_ids`` field after the ``lang`` field.
241
<record model="ir.ui.view" id="view_partner_form4">
242
<field name="name">res.partner.form.inherit4</field>
243
<field name="model">res.partner</field>
244
<field name="inherit_id" ref="base.view_partner_form"/>
245
<field name="arch" type="xml">
246
<field name="lang" position="after">
247
<field name="relation_ids"/>
252
Will add ``relation_ids`` field after the ``lang`` field.
254
.. i18n: Multiple Changes
255
.. i18n: ~~~~~~~~~~~~~~~~
261
.. i18n: To make changes in more than one location, wrap the fields in a data element.
264
To make changes in more than one location, wrap the fields in a data element.
266
.. i18n: .. code-block:: xml
268
.. i18n: <record model="ir.ui.view" id="view_partner_form5">
269
.. i18n: <field name="name">res.partner.form.inherit5</field>
270
.. i18n: <field name="model">res.partner</field>
271
.. i18n: <field name="inherit_id" ref="base.view_partner_form"/>
272
.. i18n: <field name="arch" type="xml">
274
.. i18n: <field name="lang" position="replace"/>
275
.. i18n: <field name="website" position="after">
276
.. i18n: <field name="lang"/>
285
<record model="ir.ui.view" id="view_partner_form5">
286
<field name="name">res.partner.form.inherit5</field>
287
<field name="model">res.partner</field>
288
<field name="inherit_id" ref="base.view_partner_form"/>
289
<field name="arch" type="xml">
291
<field name="lang" position="replace"/>
292
<field name="website" position="after">
299
.. i18n: Will delete the ``lang`` field from its usual location, and display it after
300
.. i18n: the ``website`` field.
303
Will delete the ``lang`` field from its usual location, and display it after
304
the ``website`` field.
306
.. i18n: .. _xpath-element-inheritance:
308
.. i18n: XPath Element
309
.. i18n: ~~~~~~~~~~~~~
312
.. _xpath-element-inheritance:
317
.. i18n: Sometimes a view is too complicated to let you simply identify a target field
318
.. i18n: by name. For example, the field might appear in two places. When that happens,
319
.. i18n: you can use an ``xpath`` element to describe where your changes should be
323
Sometimes a view is too complicated to let you simply identify a target field
324
by name. For example, the field might appear in two places. When that happens,
325
you can use an ``xpath`` element to describe where your changes should be
328
.. i18n: .. code-block:: xml
330
.. i18n: <record model="ir.ui.view" id="view_partner_form6">
331
.. i18n: <field name="name">res.partner.form.inherit6</field>
332
.. i18n: <field name="model">res.partner</field>
333
.. i18n: <field name="inherit_id" ref="base.view_partner_form"/>
334
.. i18n: <field name="arch" type="xml">
337
.. i18n: expr="//field[@name='address']/form/field[@name='email']"
338
.. i18n: position="after">
339
.. i18n: <field name="age"/>
342
.. i18n: expr="//field[@name='address']/tree/field[@name='email']"
343
.. i18n: position="after">
344
.. i18n: <field name="age"/>
350
.. i18n: Will add the ``age`` field after the ``email`` field in both the form and tree
351
.. i18n: view of the address list.
356
<record model="ir.ui.view" id="view_partner_form6">
357
<field name="name">res.partner.form.inherit6</field>
358
<field name="model">res.partner</field>
359
<field name="inherit_id" ref="base.view_partner_form"/>
360
<field name="arch" type="xml">
363
expr="//field[@name='address']/form/field[@name='email']"
368
expr="//field[@name='address']/tree/field[@name='email']"
376
Will add the ``age`` field after the ``email`` field in both the form and tree
377
view of the address list.