From f59b9fafa93c4dc100d38eba08d294d4ef906183 Mon Sep 17 00:00:00 2001 From: jvm-odoo Date: Fri, 8 Nov 2019 07:45:03 +0000 Subject: [PATCH] [FIX] crm: fix partner_id while converting a lead to an opportunity Prerequisites - Configure a mail server (incoming) - Enable leads in CRM app - Create a sales team with a mail alias (ex: testcrm@odoo.com) and check "Pipeline" and "Leads" - Set a partner email with one of yours (ex: bob@odoo.com) /!\ - Send a mail from bob to testcrm - In the incoming mail server click on "Fetch" Reproduce the issue: - Convert the generated lead to an opportunity - Choose "Existing customer" and set another one than the actual - The opportunity is created but the customer is the old one Cause: The given partner_id is overriden by the old one in the `handle_partner_assignation` method. This commit gives the priority to the new partner_id. OPW-2089404 closes odoo/odoo#40031 X-original-commit: e1833936255839cd34eba5758ca4c3124fd2522c Signed-off-by: Jason Van Malder --- addons/crm/models/crm_lead.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index b3536623b31..886f6b97cf2 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -950,6 +950,8 @@ class Lead(models.Model): """ partner_ids = {} for lead in self: + if partner_id: + lead.partner_id = partner_id if lead.partner_id: partner_ids[lead.id] = lead.partner_id.id continue @@ -957,8 +959,6 @@ class Lead(models.Model): partner = lead._create_lead_partner() partner_id = partner.id partner.team_id = lead.team_id - if partner_id: - lead.partner_id = partner_id partner_ids[lead.id] = partner_id return partner_ids