Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Form View with 4 models

By
Pedro Leite
on 4/21/16, 5:48 AM 290 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

0

Jignesh Mehta

--Jignesh Mehta--
2087
| 6 4 8
Surat, India
--Jignesh Mehta--


Jignesh Mehta
On 4/21/16, 6:09 AM

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,

@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

Prakash Sharma
on 4/21/16, 8:18 AM

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

Jignesh Mehta
on 4/21/16, 8:20 AM

@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

Bhavik Bagadiya
on 4/21/16, 8:24 AM
0
Pedro Leite
On 4/21/16, 6:36 AM

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.

see my updated ans. It will help you.

Jignesh Mehta
on 4/21/16, 7:49 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/21/16, 5:48 AM
Seen: 290 times
Last updated: 4/21/16, 6:36 AM