Reputation: 77
I'm writing a module to manage some sort of branches.
Every branch can contain sub-branches.
There is a field (type) which determines the type of the branch (sub or main).
_columns = {
'name' : fields.char('Name',size=120,required=True),
'no' : fields.char('Number'),
'type' : fields.selection([('s','Sub'), ('m','Main Branch ')],'Type',help="Branch type: Main or Sub branch."),
I need to show this hierarchy in a view in OpenERP.
I can use the normal tree view like this:
<!-- Tree view of branches -->
<record id="view_branch_tree" model="ir.ui.view">
<field name="name">branchs.branch.tree</field>
<field name="model">branchs.branch</field>
<field name="arch" type="xml">
<tree string="station" >
<field name="name"/>
<field name="no"/>
<field name="type"/>
But I don't know how to show them in a hierarchical tree, with main branches as nodes like an account chart.
Upvotes: 0
Views: 1412
Reputation: 612
You will need to do the following:
1- In the .py file add a column of type (one2many) that will have the ids of the children and another one that refers to the parent :
'parent_id' : fields.many2one('branches.branch','Parent Branches'),
'child_ids' : fields.one2many('branches.branch', 'parent_id', 'Children'),
2- In the xml file: add this this field: child_ids
And in the section change the viewtype to tree:
<field name="view_type">tree</field>
Finally, add this filter in order to show only the parents in the nodes:
<field name="domain">[('parent_id','=',False)]</field>
That's it.
Upvotes: 2