I have a nested field in my XML file and I want to modularize it. For example, I have a model with the field One2many
. When I call the One2many
field in XML, I need to provide the form & tree view.
<!-- Parent Form -->
<record id="view_rm_reservation_form" model="ir.ui.view">
<field name="name">rm.reservation.form</field>
<field name="model">rm.reservation</field>
<field name="arch" type="xml">
<form>
<sheet>
...
...
<!-- One2many -->
<field name="order_line_ids">
<!-- One2many Tree -->
<tree create="1">
...
...
</tree>
<!-- One2many Form -->
<form create="0">
...
...
</form>
</field>
...
...
</sheet>
</form>
</field>
</record>
I want to put the One2many Tree
and One2many Form
into a separate file. How I can do this? Is this even possible?
CodePudding user response:
Yes that is possible. Just create a form and tree view for the model behind that one2many
field and then "call" those views on the model of that field.
Presumptions: You have a form view my_module.view_sub_model_form
and tree view my_module.view_sub_model_tree
for the model behind the one2many
field. The field itself is like in your example order_line_ids
.
So you just do the following to use the views:
<field name="order_line_ids"
context="{'tree_view_ref': 'my_module.view_sub_model_tree',
'form_view_ref': 'my_module.view_sub_model_form'}" />
When creating new "basic views" (not extending existing ones) keep an eye on the priority field of the views, because that one is important for the order of retrieving views by Odoo. Not setting it will lead to value 16
, and should be fine in most situations. When using such special views only for one2many fields, i would set it atleast one higher to 17
.
<record id="view_sub_model_form" model="ir.ui.view">
<field name="name">sub.model.form</field>
<field name="model">sub.model</field>
<field name="priority" eval="17" />
<field name="arch" type="xml">
</field>
</record>