Hi,
In Odoo 10, you can create a tree view inside another tree view by defining related fields and using the groups
feature in the XML view definition. This allows you to display related
records as a nested tree view within the parent tree view.
Here's a step-by-step guide on how to achieve this:
- Define
Related Fields:
First, you need to define related fields in your model. These related
fields will establish the relationship between the parent and child
records.For example, let's assume you have two models: parent.model and child.model. You want to display a list of related child.model records within the parent.model tree view. You would define a related field in the parent.model like this:
from odoo import models, fields
class ParentModel(models.Model):
_name = 'parent.model'
_description = 'Parent Model'
name = fields.Char(string='Name')
child_ids = fields.One2many('child.model', 'parent_id', string='Children')
Define the Parent Tree View:
In your XML view definition for the parent.model, define a tree view for it. Include the related field child_ids to display the related records.
<record id="view_parent_model_tree" model="ir.ui.view">
<field name="name">parent.model.tree</field>
<field name="model">parent.model</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="child_ids" widget="one2many_list">
<form string="Child Records">
<field name="field1"/>
<field name="field2"/>
<!-- Add more fields as needed -->
</form>
</field>
</tree>
</field>
</record>
- The widget="one2many_list" attribute tells Odoo to display the related records as a nested list view within the parent tree view.
- Define the Child Tree View (Optional):
If you want to customize the tree view for the child.model, you can define a separate tree view for it in a similar way.
- Apply
Security Groups (Optional):
If you want to restrict access to certain records, you can use Odoo's
security groups to control who can see the child records within the
parent tree view.
Once you've defined the related fields
and created the appropriate views, you should be able to see the child
records displayed as a nested tree view within the parent tree view.
Keep
in mind that this approach allows you to display related records in a
nested fashion within the parent tree view. If you need more complex
tree view structures, you might need to explore custom Odoo module
development or consult with an Odoo developer for additional
customization.
Hope it helps