From 3a8ae4bc893159c83130331b287478a21256188c Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Thu, 12 Aug 2021 07:29:45 +0000 Subject: [PATCH] [FIX] sale_crm: always create a new customer when create is selected When clicking on the 'New quotation' action, if no current customer is linked to the lead, a popup opens with the following options: - Create a new customer - Link to an existing customer - Do not link to a customer If odoo found a potential matching customer but we decide it is the wrong one and select the first option, a new one should always be created opw-2545065 Task-2622793 closes odoo/odoo#75213 X-original-commit: 728f8611caa8fe3f3bdc88a9650f7edb05321a87 Signed-off-by: Hubert Van De Walle Signed-off-by: Thibault Delavallee (tde) --- .../tests/test_crm_lead_convert_quotation.py | 20 +++++++++++++++++++ .../wizard/crm_opportunity_to_quotation.py | 6 ++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/addons/sale_crm/tests/test_crm_lead_convert_quotation.py b/addons/sale_crm/tests/test_crm_lead_convert_quotation.py index 0032bad11c4..7185a33285c 100644 --- a/addons/sale_crm/tests/test_crm_lead_convert_quotation.py +++ b/addons/sale_crm/tests/test_crm_lead_convert_quotation.py @@ -76,6 +76,26 @@ class TestLeadConvertToTicket(crm_common.TestCrmCommon): self.assertEqual(lead.mobile, self.contact_2.mobile) self.assertEqual(action['context']['default_partner_id'], self.contact_2.id) + @users('user_sales_salesman') + def test_lead_convert_to_quotation_false_match_create(self): + lead = self.lead_1.with_user(self.env.user) + + # invoke wizard and apply it + convert = self.env['crm.quotation.partner'].with_context({ + 'active_model': 'crm.lead', + 'active_id': lead.id, + }).create({'action': 'create'}) + + convert.write({'partner_id': self.contact_2.id}) + + self.assertEqual(convert.action, 'create') + + # ignore matching partner and create a new one + convert.action_apply() + + self.assertTrue(bool(lead.partner_id.id)) + self.assertNotEqual(lead.partner_id, self.contact_2) + @users('user_sales_salesman') def test_lead_convert_to_quotation_nothing(self): """ Test doing nothing about customer while converting """ diff --git a/addons/sale_crm/wizard/crm_opportunity_to_quotation.py b/addons/sale_crm/wizard/crm_opportunity_to_quotation.py index 24a18383581..4442945eda9 100644 --- a/addons/sale_crm/wizard/crm_opportunity_to_quotation.py +++ b/addons/sale_crm/wizard/crm_opportunity_to_quotation.py @@ -45,6 +45,8 @@ class Opportunity2Quotation(models.TransientModel): the freshly created opportunity view. """ self.ensure_one() - if self.action != 'nothing': - self.lead_id._handle_partner_assignment(force_partner_id=self.partner_id.id, create_missing=(self.action == 'create')) + if self.action == 'create': + self.lead_id._handle_partner_assignment(create_missing=True) + elif self.action == 'exist': + self.lead_id._handle_partner_assignment(force_partner_id=self.partner_id.id, create_missing=False) return self.lead_id.action_new_quotation()