Skip to Content
Menu
This question has been flagged
2 Replies
4255 Views

How do I create a hierarchical view in Odoo 17?

The option described in the article https://www.cybrosys.com/blog/how-to-create-a-hierarchical-view-in-odoo-17 doesn't work.

On my view (as in article)

i'm getting a message

"The root node of a tree view should be a  tree, not a hierarch.


Avatar
Discard
Best Answer

Hi,

1)Inside heirarchy_details.py file provide the code


from odoo import fields, models


class DepartmentDetails(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')


Note : give heirarchy_details.py file in your __init__ file


2) in the security file give :

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
heirarchy_view.access_department_details,access_department_details,heirarchy_view.model_department_details,base.group_user,1,1,1,1

3) In the heirarchy_menus.xml file provide:


<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <menuitem id="heirarchy_manager_menu"
              name="License Manager"
              sequence="0"/>
    <menuitem id="heirarchy_list_menu"
              name="Heirarchy List"
parent="heirarchy_manager_menu"
              action="heirarchy_list_action"
              sequence="0"/>
</odoo>

4)In heirarchy_views.xml file provide

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_department_details_tree" model="ir.ui.view">
<field name="name">view.department.details.tree</field>
<field name="model">department.details</field>
        <field name="arch" type="xml">
            <tree>
                <field name="department"/>
                <field name="parent_id"/>
                <field name="child_ids"/>
            </tree>
        </field>
    </record>
<record id="view_department_details_form" model="ir.ui.view">
<field name="name">view.department.details.form</field>
<field name="model">department.details</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <group>
                        <field name="department"/>
                        <field name="parent_id"/>
                        <field name="child_ids"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

<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>
    <record id="heirarchy_list_action" model="ir.actions.act_window">
        <field name="name">Department Manager</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">department.details</field>
<field name="view_mode">tree,form,hierarchy</field>
        <field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
                No data yet!
            </p>
            <p>Create department Records.
            </p>
        </field>
    </record>
</odoo>

Note:

 Add your models directory in your main __init__ file, also configure your __manifest__ file.


If you done all the above steps properly , then the output will be like:


Hope it helps


Avatar
Discard

hi, i followed your code but im encountered an eror, is it because im using odoo 16? could you help me?

raise ValueError("Wrong value for %s: %r" % (self, value))
ValueError: Wrong value for ir.ui.view.type: 'hierarchy'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/opt/odoo/odoo-server/odoo/http.py", line 1998, in __call__
response = request._serve_db()
File "/opt/odoo/odoo-server/odoo/http.py", line 1563, in _serve_db
self.registry = Registry(self.db).check_signaling()
File "/opt/odoo/odoo-server/odoo/modules/registry.py", line 66, in __new__
return cls.new(db_name)
File "<decorator-gen-14>", line 2, in new
File "/opt/odoo/odoo-server/odoo/tools/func.py", line 87, in locked
return func(inst, *args, **kwargs)
File "/opt/odoo/odoo-server/odoo/modules/registry.py", line 90, in new
odoo.modules.load_modules(registry, force_demo, status, update_module)
File "/opt/odoo/odoo-server/odoo/modules/loading.py", line 484, in load_modules
processed_modules += load_marked_modules(cr, graph,
File "/opt/odoo/odoo-server/odoo/modules/loading.py", line 372, in load_marked_modules
loaded, processed = load_module_graph(
File "/opt/odoo/odoo-server/odoo/modules/loading.py", line 231, in load_module_graph
load_data(cr, idref, mode, kind='data', package=package)
File "/opt/odoo/odoo-server/odoo/modules/loading.py", line 71, in load_data
tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind)
File "/opt/odoo/odoo-server/odoo/tools/convert.py", line 763, in convert_file
convert_xml_import(cr, module, fp, idref, mode, noupdate)
File "/opt/odoo/odoo-server/odoo/tools/convert.py", line 829, in convert_xml_import
obj.parse(doc.getroot())
File "/opt/odoo/odoo-server/odoo/tools/convert.py", line 749, in parse
self._tag_root(de)
File "/opt/odoo/odoo-server/odoo/tools/convert.py", line 711, in _tag_root
raise ParseError('while parsing %s:%s, somewhere inside\n%s' % (
odoo.tools.convert.ParseError: while parsing /opt/odoo/Prestaterre/Prestaterre/certification_app/views/partner.xml:93, somewhere inside
<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>

Author Best Answer

Thank you very much, it works. Only in the security file, instead of heirarchy_view.model_department_details, there should be model_department_details

Avatar
Discard
Related Posts Replies Views Activity
4
May 25
2592
2
May 25
5986
1
Mar 25
1722
4
Mar 25
4585
3
Feb 25
5593