Ma7
Ma7

Reputation: 229

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

Upvotes: 1

Views: 3262

Answers (2)

Pablo Escobar
Pablo Escobar

Reputation: 685

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 !

Upvotes: 3

aekis.dev
aekis.dev

Reputation: 2754

For that you will need to define a field of type One2many or Many2many to be able to show it as a tree view relation in your form. You could have nested the <tree/> definition of your o2m or m2m field with the fields to show from the relation model nested in your field, like:

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

I didn't have used exactly your view definition because images cannot be copied into gedit, but you could get the idea from the example

Upvotes: 1

Related Questions