1
votes

I'm trying to recreate the Company's Structure view from Odoo.

I have created my model with parent_id and child_ids according to res.company sample.

But it didn't work. Here is my XML

<record id="open_module_tree_my_department_my" model="ir.actions.act_window">
    <field name="name">My Department</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">my.department</field>
    <field name="domain">[('parent_id','=',False)]</field>
    <field name="view_type">tree</field>
</record>

Here is my model

class MyDepartment(models.Model):
    _name = 'my.department'
    _description = 'My Department'

    name = fields.Char(string="My Department", required=True)

    parent_id = fields.Many2one("my.department", "Parent Department", select=True)
    child_ids = fields.One2many("my.department", "parent_id", string="Children")

What am I missing?

2

2 Answers

1
votes

Turned out I only need to add a view for the model

<record id="view_my_department_list" model="ir.ui.view">
    <field name="name">my.department.tree</field>
    <field name="model">my.department</field>
    <field name="type">tree</field>
    <field name="field_parent">child_ids</field>
    <field name="arch" type="xml">
        <tree string="My Departments">
            <field name="name"/>
            <field name="parent_id" invisible="1"/>
        </tree>
    </field>
</record>

<record id="open_module_tree_my_department_my" model="ir.actions.act_window">
    <field name="name">My Department</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">my.department</field>
    <field name="domain">[('parent_id','=',False)]</field>
    <field name="view_type">tree</field>
    <field name="view_id" ref="view_my_department_list"/>
</record>
0
votes

@strike_noir as I know 'field_parent' is removed from Odoo 11, what's your other adaptions for the hierarchical tree view in odoo11+.

Thank you.