This question has been flagged
1 Reply
2241 Views

Hi all,

V 10.0

I have a situation where two m2m fields are shown on a model.

Records from the second m2m field (displayed as kanban) have to be added or removed from the first m2m (displayed as a tree).

I am confused as to how to define the  "add_record_to_m2m_1" action (see below).
Does it have to be defined at the "test.model" level or at the "product.template" level ?

When calling the action is "self" the "test.model" record or the "product.template" record ?

and how to refer to the other one ? context ? records ? uid ? .. is it even possible ?


Thanks for the input.


Model :

Class TestModel(models.Model):

    _name = "test.model"

    m2m_1 =fields.Many2many(comodel_name="product.template")

     m2m_2 =fields.Many2many(comodel_name="product.template")


View :

<form>

    <field name="m2m_1">

        <tree>

                <field name="name"/>

        </tree>

    </field>

    <field name="m2m_2" widget="many2many_kanban">

        <kanban>

                <field name="name"/>

                <button action="add_record_to_m2m_1"/>

        </kanban>

    </field>

<form>


Avatar
Discard

You must know how to do customization in odoo, reference: https://www.scoop.it/t/learn-openerp

Best Answer

If you don't specify the relation table when define Many2many field odoo will create a new table name "test_model_product_template_rel" as relation table between "test.model" and "product.template", which mean your "m2m_1" and "m2m_2" are using the same relation table, if you want to separate them then you need to add "relation" option when m2m_2 is defined such as:

m2m_2 =fields.Many2many(comodel_name="product.template", relation="test_model_product_template_rel_2", column1="test_id", column2="product_tmpl_id")

and the "self" will be product.template
Avatar
Discard