Odoo lets you extend models easily using the _inherit
field. Common code and fields of the base model can thus be accessed in extending models.
My question is: can I structure my xml files (e.g. search views, form views, etc.) of the extending models to also reuse common xml code of the base models?
I have read that the template include mechanism (using t-call
) does only work for QWeb templates, but not in general for xml views (see include templates).
And the view inheritance using inherit_id
as I understand, only extends an existing view for a given model. However it does not make it possible to include parts of existing views to create a new one.
So does this mean I have to copy the common xml code for fields in the base model to all views that extend this model?
Example:
Model inheritance
class Base(models.Model):
_name = 'bla.base'
common1 = fields.Text()
common2 = fields.Text()
class ExtA(models.Model):
_name = 'bla.exta'
_inherit = ['bla.base']
field_x = fields.Integer()
class ExtB(models.Model):
_name = 'bla.extb'
_inherit = ['bla.base']
field_y = fields.Integer()
Views
<record model="ir.ui.view" id="exta_search">
<field name="name">exta.search</field>
<field name="model">bla.exta</field>
<field name="arch" type="xml">
<search>
<field name="field_x"/>
<!-- Also include xml to search in base model -->
</search>
</field>
</record>
<record model="ir.ui.view" id="extb_search">
<field name="name">extb.search</field>
<field name="model">bla.extb</field>
<field name="arch" type="xml">
<search>
<field name="field_y"/>
<!-- Also include xml to search in base model -->
</search>
</field>
</record>
_inherits
(delegation) inheritance instead? View inheritance will work there. An example is Odoo's models product.template and product.product. - CZoellner