Skip to Content
Menu
This question has been flagged
2 Replies
3321 Views

Odoo 12.0 in docker container.

Hello, 

I'm building a module that connect a custom model to existing crm.lead model. So far so good.

My model : 

class zpintervention(models.Model):  
  _name = 'zptunnel.intervention'
_description = 'Interventions'

_defaults = {
'lead_id': lambda self: self.env.context.get('lead_id', False),
}

name = fields.Char(string="Nom", required=True)
description = fields.Text()

lead_id = fields.Many2one('crm.lead', ondelete='cascade', string="Piste", required=True, index=True)

class zpleads(models.Model):
_inherit = 'crm.lead'
_description = 'Leads (Custom)'

  intervention_ids = fields.One2many('zptunnel.intervention', 'lead_id', string="Interventions")​

Now I want to alter the leads form so that I can create the related entity for my leads. It works fine, but I have to specify manually the parent lead. I've tried with many2many_list widget as well as kanban, but it looks like the context is not taken into account. What's wrong with my code ?

My view :

<record model="ir.ui.view" id="zptunnel_zpleads_leads">
<field name="name">Pistes (ZP)</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads"/>
<field name="priority" eval="15"/>
<field name="arch" type="xml">

  <xpath expr="//notebook" position="before">

    <form string="Intervention">
      <sheet>
        <group>
          <group>
            <field name="intervention_ids" mode="kanban" context="{'lead_id': active_id}">    
              <kanban>
  <field name="id"/>
  <field name="name"/>
  <field name="lead_id"/>
  <templates>
                    <t t-name="kanban-box">
  <div>
  <div class="oe_kanban_details">
  <div>
  <field name="name"/>
  </div>
  </div>
                      </div>
                    </t>
                  </templates>
                </kanban>
  </field>
            </group>
          </group>
        </sheet>
  </form>

  </xpath>

</field>
</record>​
Avatar
Discard
Best Answer

Hello,

Edit this line as given below,

<field name="intervention_ids" mode="kanban" context="{'default_lead_id': active_id}">

remove this line


  _defaults = {
'lead_id': lambda self: self.env.context.get('lead_id', False),
}

Avatar
Discard
Author Best Answer

Hello,

Yes it works ! Thank you !

Alain

Avatar
Discard