How to Generate a Hierarchical View in Odoo 17

Odoo enjoys global recognition as one of the most user-friendly business management software suites, playing a vital role in efficiently managing various business departments. Moreover, this open-source ERP is complemented by a wide array of interconnected management modules, such as CRM, Sales, Purchase, HR, Accounting, Point of Sale, and more, aimed at streamlining a substantial portion of corporate operations.

In Odoo programs, data is structured as objects and represented through Odoo views. Odoo supports various forms of data representation, including the tree view, list view, kanban view, cohort view, pivot view, and calendar view. The hierarchical view, introduced in Odoo 17, provides a structured and organized representation of data, thereby enhancing the platform's capabilities for effective information visualization.

This blog explores the process of crafting a basic hierarchical view in Odoo 17.

Structured view:

Specify the Python Model as illustrated below:

Initially, we need to establish a new model, for example: 'department.details'.

Below is the code for establishing a department model and ensuring that 'parent_id' and 'child_ids' are modeled as 'department.details'.

classDepartmentDetails(models.Model):
    _name = 'department.details'
    _description = 'create a new model for hierarchy'
    _rec_name = 'department'
    department = fields.Char()
    parent_id = fields.Many2one("department.details")
   child_ids = fields.One2many("department.details",'parent_id')

Specify the XML view as depicted below:

To define the XML view, utilize the following command:

Initially, we need to create an action for this model.

<record id="department_details_action" model="ir.actions.act_window">
        <field name="name">Department details</field>
        <field name="res_model">department.details</field>
        <field name="view_mode">tree,form,kanban,hierarchy</field>
    </record>

XML code for structured view:

<record id="department_details_view_hierarchy" model="ir.ui.view">
        <field name="name">department.details.view.hierarchy</field>
        <field name="model">department.details</field>
        <field name="arch" type="xml">
            <hierarchy child_field="child_ids"
                        draggable="1">
                <field name="department"/>
                <templates>
                    <t t-name="hierarchy-box">
                        <div t-attf-class="o_hierarchy_node_header d-flex justify-content-center pb-4"
                             t-att-title="parent_id">
                        </div>
                        <div class="o_hierarchy_node_body d-flex flex-column text-center">
                            <div class="w-100 position-relative">
                                <field class="fw-bold" name="department"/><br/>
                            </div>
                        </div>
                    </t>
                </templates>
            </hierarchy>
        </field>
    </record>

Add Security:

Additionally, include security measures as follows:

id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_department_details,access_department.details,model_department_details,base.group_user,1,1,1,1

Here, we can observe the output as follows:


The advanced hierarchical view feature within the Odoo platform enhances the efficiency of various menu functions, thereby contributing to streamlined operations and improving the platform's effectiveness in business management.

How to Handle Company Assets and Depreciation in Odoo 17 Accounting