This question has been flagged
2 Replies
3254 Views

Hi,

 I have a form view with 3 pages in the notebook. I need to have 3 models in the same form, but the ODOO only allows one. Is there any way around this?


Best regards

Avatar
Discard
Best Answer

Hello Pedro,


For this, you can use _inherits concepts of odoo.

For Ex :-

class MainModel(models.Model):

     _name = 'main.model'

      _inherits = {'model.a': 'a_id', 'model.b': 'b_id', 'model.c':'c_id'}

     a_id = fields.Many2one('model.a', 'A')

     b_id = fields.Many2one('model.b', 'B')

     c_id = fields.Many2one('model.c', 'C')

     # another fields which you want to display


class ModelA(models.Model):

     _name = 'model.a'

     a_name = fields.Char('A Name')

     # another fields for A model

class ModelB(models.Model):

     _name = 'model.b'

     b_name = fields.Char('B Name')

     # another fields for A model


class ModelC(models.Model):

     _name = 'model.c'

     c_name = fields.Char('C Name')

     # another fields for A model


In Xml :-

<record id="new_view" model="ir.ui.view">
    <field name="name">main.model</field>
    <field name="model">main.model</field>
    <field name="arch" type="xml">
        <form> 
            <sheet>     
                <notebook>
                    <page string="A">
                        <field name="a_name"/>
                    </page>
                    <page string="B">
                        <field name="b_name"/>
                    </page>
                    <page string="C">
                        <field name="c_name"/>
                    </page>                    
                </notebook>
        </sheet>
      </form>
    </field>
</record>

Hope it works for you.

Thanks,

Avatar
Discard

@Jignesh Mehta, you have change the "has a" relation in the "is a" relation , it will create a huge burden on db schema as the data size grow in MOdel A,B and C , this is not right

Hello @Prakash, This is the only way to do that for @Pedro's situation.

@Prakash Sharma in odoo we have a facility of _inherits so we can use relation to use data like as example given by @Jignesh Mehta so we can use this way , and from my point of view @Jignesh Mehta is right. Thanx

Author Best Answer

Hi @Jigness Mehta,

thanks for the answer. I already have this structure, the problem is I want to put a form in each page of the notebook. I tried to do this:

<field name="payment_ids">
   <form string="Payments">
        <field name="name"/>
    </form>
</field>

However, this form only appears when I click "Add an item" in the list that appears by default, because the field "payment_ids" is a One2Many.

Avatar
Discard

see my updated ans. It will help you.