I have transferred the _track_subtype method from the CRM module to my module and inserted the is_lost field, which changes the status to true when the lead is moved to the stage with the label lost. It is just that the state does not always change. If I now move it back to another stage, it remains lost with the heading at the top right. Only when I refresh the page is the state updated and the heading disappears.
How can I reload the Kanban view in Odoo after moving a lead to a different stage?
class Lead(models.Model):
_inherit = 'crm.lead'
is_lost = fields.Boolean(string='Is Lost', default=False)
def _track_subtype(self, init_values):
self.ensure_one()
if self.stage_id.name.find("Lost") != -1:
# If a lead is moved to Lost, then set is_lost to True
self.is_lost = True
else:
# For all other lead set is_lost to False
self.is_lost = False
if 'stage_id' in init_values and self.probability == 100 and self.stage_id:
return self.env.ref('crm.mt_lead_won')
elif 'lost_reason_id' in init_values and self.lost_reason_id:
return self.env.ref('crm.mt_lead_lost')
elif 'stage_id' in init_values:
return self.env.ref('crm.mt_lead_stage')
elif 'active' in init_values and self.active:
return self.env.ref('crm.mt_lead_restored')
elif 'active' in init_values and not self.active:
return self.env.ref('crm.mt_lead_lost')
return super(Lead, self)._track_subtype(init_values)
<record id="mymodule_crm_case_kanban_view_leads" model="ir.ui.view">
<field name="name">mymodule.crm.lead.kanban.lead</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_kanban_view_leads"/>
<field name="arch" type="xml">
<!-- Aperture with red background and white lettering 'Lost' in the window -->
<xpath expr="//widget[@name='web_ribbon']" position="replace">
<field name="is_lost" invisible="0"/>
<widget name="web_ribbon" title="lost" bg_color="text-bg-danger" invisible="is_lost == False"/>
</xpath>
</field>
</record>
Hi, there is still the error, now it is not updated when i move it back to lost. i think i have to use javascript here. i use odoo 18. how can i integrate javascript. i don't know anything about this. Could you describe this in detail.