Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
6089 Vizualizări

Hello, I have a problem with my M2M fields. When we modify one, the other is modified with the new values of the first one.

crm_lead.py :

class Lead(models.Model):
    _inherit = 'crm.lead'
    business_provider = fields.Many2one(comodel_name='res.partner', string='Business provider', domain='["|",("est_consultant_externe","=",True),("user_ids","!=",False),("user_ids.share", "=",False)]')
    internal_consultant_ids = fields.Many2many(comodel_name='res.partner', string='Internal consultant', domain='[("user_ids","!=",False),("user_ids.share", "=",False)]')
    external_consultant_ids = fields.Many2many(comodel_name='res.partner', string='External consultant', domain='[("est_consultant_externe","=",True)]')

crm_lead_view_form.xml :

<odoo>
  <data>
    <!-- crm.lead inherit form view -->
    <record id="lgp_crm_lead_inherit_view_form" model="ir.ui.view">
      <field name="name">lgp.crm.lead.inherit.view.form</field>
      <field name="model">crm.lead</field>
      <field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
      <field name="arch" type="xml">
        <xpath expr="//field[@name='user_id']" position="after">
          <field name="apporteur_affaire"/>
          <field name="consultant_interne_ids" widget="many2many_tags"/>
          <field name="consultant_externe_ids" widget="many2many_tags"/>
        </xpath>
      </field>
    </record>
  </data>
</odoo>

How can I resolve this problem, please ?

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

in your many2many explicitly specify the relation and columns. E.g.:

internal_consultant_ids = fields.Many2many(
    comodel_name='res.partner',
    "crm_lead_res_partner_int_rel",
    "crm_lead_int_id",
    "res_partner_int_id",
   string='Internal consultant',
    domain='[("user_ids","!=",False),("user_ids.share", "=",False)]'
)
external_consultant_ids = fields.Many2many(
    comodel_name='res.partner',
    "crm_lead_res_partner_rel_ext",
    "crm_lead_ext_id",
    "res_partner_ext_id",
    string='External consultant',
    domain='[("est_consultant_externe","=",True)]'
)


Have also a look at the documentation: https://www.odoo.com/documentation/12.0/reference/orm.html#relational-fields

Imagine profil
Abandonează
Autor

It work, thank you.

Cel mai bun răspuns

Hello Valentin,

Here you didn't give any relational table name, so system will create one table with combination of two table names. if you give many2many relation with same table but multiple fields means the system will refer single relational table. So you have to pass different relational table for each many2many field.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
nov. 19
5139
2
iun. 20
11401
0
sept. 24
1063
2
dec. 19
6484
2
sept. 18
9619