Search code examples
odooodoo-10

How to add an tree view inside a notbook form in odoo?


i want to add an tree view in a custom module like this : enter image description here

this is my XML File : enter image description here


Solution

  • Mahmoud, For the notebook need a One2many field in main class to the notebook's class and need a Many2one field from notebook's class to the main class. And add that One2many field in the xml before the tree tag.

    For example:

    class Mainclass(models.Model):
    _name = 'main.class'
        notebook_ids = fields.One2many('notebook.class', 'main_class_id', string="Notebook")
    
    
    class NotebookClass(models.Model):
    _name = 'notebook.class'
          main_class_id = fields.Many2one('main.class', string="Main Class")
          name = fields.Char(string="Name")
          state = fields.Char(string="state")
    

    In the XML you have to add,

    <notebook>
        <page>
            <field name="notebook_ids">
                <tree>
                    <field name="name"/>
                    <field name="state"/>
                </tree>
            </field>
        </page>
    </notebook>
    

    Add One2many field on wherever you need to add a notebook. And notebook field's should be written in an another class.

    Thanks in advance ! Happy Coding !