From 3f232cb6e95b7cd15259aea3533d5ab1522a4fb2 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Mon, 26 Apr 2021 13:39:54 +0000 Subject: [PATCH] [FIX] event_crm: fix False - False lead creation Use Case -------- Have two (or more) rules with mutually exclusive domain for that can be apply on the same event with lead_creation_basis = order Create a registration that match one of the rule Problem ------- The lead for this rule is created properly but there is also another lead with the name False - False that is created for the second rule for which the registration does not match the filter Solution -------- Create a lead only when there is a non empty record set in the registration group closes odoo/odoo#70590 X-original-commit: 43fc8dac5e21a9aecf7b2950a6c3c77d8142ee45 Signed-off-by: Thibault Delavallee (tde) --- addons/event_crm/models/event_lead_rule.py | 2 +- addons/event_crm/tests/test_event_crm_flow.py | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/event_crm/models/event_lead_rule.py b/addons/event_crm/models/event_lead_rule.py index 47c425fef26..08c5c114cb0 100644 --- a/addons/event_crm/models/event_lead_rule.py +++ b/addons/event_crm/models/event_lead_rule.py @@ -180,7 +180,7 @@ class EventLeadRule(models.Model): 'description': "%s\n%s" % (lead.description, additionnal_description), 'registration_ids': [(4, reg.id) for reg in group_registrations], }) - else: + elif group_registrations: lead_vals_list.append(group_registrations._get_lead_values(rule)) return self.env['crm.lead'].create(lead_vals_list) diff --git a/addons/event_crm/tests/test_event_crm_flow.py b/addons/event_crm/tests/test_event_crm_flow.py index 3c289f49e58..74352c775db 100644 --- a/addons/event_crm/tests/test_event_crm_flow.py +++ b/addons/event_crm/tests/test_event_crm_flow.py @@ -166,3 +166,23 @@ class TestEventCrmFlow(TestEventCrmCommon): registration.action_set_done() self.assertLeadConvertion(self.test_rule_order_done, registration) + + @users('user_eventmanager') + def test_order_rule_duplicate_lead(self): + """ Check when two rules match one event + but only one match the registration, + only one lead should be created + """ + test_rule_order_2 = self.test_rule_order.copy(default={ + 'event_registration_filter': [['email', 'not ilike', '@test.example.com']] + }) + self.env['event.registration'].create({ + 'name': 'My Registration', + 'partner_id': False, + 'email': 'super.email@test.example.com', + 'phone': False, + 'mobile': '0456332211', + 'event_id': self.event_0.id, + }) + self.assertEqual(len(self.test_rule_order.lead_ids), 1) + self.assertEqual(len(test_rule_order_2.lead_ids), 0)