Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
15813 Lượt xem

Hi !

I've created a simple module on Odoo v8, with two objects:

        class repas(osv.osv):
            _name = 'repas'
            _description = 'Repas de chocapic'
            _columns = {
                'name': fields.char('Nom'),
                'quantity' : fields.integer(u'Quantité'),
                'bol_id': fields.many2one('bol',u'Bol utilisé'),
            }
            _defaults = {
                'quantity': 0, 
            }

        class bol(osv.osv):
            _name = 'bol'
            _columns = {
                'name': fields.char('Nom de mon bol'),
                'repas_ids': fields.one2many('repas','bol_id','Repas'),
            }

With this view:

        <record id="bol_form_view" model="ir.ui.view">
            <field name="name">bol.form</field>
            <field name="model">bol</field>
            <field name="arch" type="xml">
                <form string="Bol">
                    <sheet>
                        <group>
                            <field name="name"/>
                        </group>
                        <group>
                            <field name="repas_ids"/>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>


When I create a "bol", I can't select an existing "repas" and I must create one, but I've a one2many relation on this !

Anyone have this problem too ? Or a solution ?

Thank you

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Same problem 5 years later in Odoo v11...

Ivan solution did not work, I had to replace "many2many_list" by "many2many" :

<field name="your_one2many_field" widget="many2many"/>

It opens a search for existing entity form, instead of opening the default create form.

Ảnh đại diện
Huỷ bỏ

worked for me on odoo 13

Worked for us on odoo 13, with similar need.

Câu trả lời hay nhất

Florent, one2many relation field is meant for you to create a new record instead of attaching something that has been created beforehand.  If you require to attach some pre-created record to a one2many field, try to use widget="many2many_list" in the <field name="repas_ids"/> in your view.

Ảnh đại diện
Huỷ bỏ

didn't work with odoo 13

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 9 23
144
2
thg 8 23
21602
1
thg 4 17
5786
1
thg 5 24
10493
0
thg 3 24
1512