From 29398abb4ec3b5c757a7410b9c65abb50e5ccb9d Mon Sep 17 00:00:00 2001 From: "Nasreddin (bon)" Date: Wed, 31 Mar 2021 17:34:25 +0000 Subject: [PATCH] [FIX] crm: display right partner and action when converting lead Issue - Create a partner with email 'aaa@test.com' - In CRM settings, activate 'Leads' feature - Go to CRM -> Leads and create a Lead: - Set email field to 'aaa@test.com' - Click on 'Convert to opportunity' Neither the action or partner_id field is set to the right value. Cause Due to missing 'lead_id' field in template, the partner_id field is not recomputed since action is not recomputed. Solution Add 'lead_id' field as invisible in form. opw-2439722 Task ID-2452777 COM PR odoo/odoo#68618 X-original-commit: 6915d17f5f10737c03c820b69eded3a7c0151907 --- addons/crm/tests/test_crm_lead_convert.py | 23 +++++++++++++++++++ addons/crm/wizard/crm_lead_to_opportunity.py | 2 +- .../wizard/crm_lead_to_opportunity_views.xml | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/addons/crm/tests/test_crm_lead_convert.py b/addons/crm/tests/test_crm_lead_convert.py index 63a81cc5de5..48502f57154 100644 --- a/addons/crm/tests/test_crm_lead_convert.py +++ b/addons/crm/tests/test_crm_lead_convert.py @@ -5,6 +5,29 @@ from odoo import SUPERUSER_ID from odoo.addons.crm.tests import common as crm_common from odoo.fields import Datetime from odoo.tests.common import tagged, users +from odoo.tests.common import Form + +@tagged('lead_manage') +class TestLeadConvertForm(crm_common.TestLeadConvertCommon): + + @users('user_sales_manager') + def test_form_action_default(self): + """ Test Lead._find_matching_partner() """ + lead = self.env['crm.lead'].browse(self.lead_1.ids) + customer = self.env['res.partner'].create({ + "name": "Amy Wong", + "email": '"Amy, PhD Student, Wong" Tiny ' + }) + + wizard = Form(self.env['crm.lead2opportunity.partner'].with_context({ + 'active_model': 'crm.lead', + 'active_id': lead.id, + 'active_ids': lead.ids, + })) + + self.assertEqual(wizard.name, 'convert') + self.assertEqual(wizard.action, 'exist') + self.assertEqual(wizard.partner_id, customer) @tagged('lead_manage') diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index 2a4eef8a447..72d0e236f64 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -77,7 +77,7 @@ class Lead2OpportunityPartner(models.TransientModel): convert.lead_id.partner_id.email if convert.lead_id.partner_id.email else convert.lead_id.email_from, include_lost=True).ids - @api.depends('action') + @api.depends('action', 'lead_id') def _compute_partner_id(self): for convert in self: if convert.action == 'exist': diff --git a/addons/crm/wizard/crm_lead_to_opportunity_views.xml b/addons/crm/wizard/crm_lead_to_opportunity_views.xml index 23e2ef5d8f6..fa7a1215781 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity_views.xml +++ b/addons/crm/wizard/crm_lead_to_opportunity_views.xml @@ -13,6 +13,7 @@ +