[FIX] event_crm: compare email based on normalized version when possible
When checking if partner and registration have the same email, better compare normalized versions if possible as it filters out formatting differences e.g. if one input has a formatted email with another name. Task-3431124 X-original-commit: 1f2a08e6b0880d20f877a73badd3b071939bcc13 Part-of: odoo/odoo#129269
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import api, fields, models, tools, _
|
||||
from odoo.addons.phone_validation.tools import phone_validation
|
||||
|
||||
|
||||
@@ -195,10 +195,18 @@ class EventRegistration(models.Model):
|
||||
) # CHECKME: broader than just public partner
|
||||
|
||||
# mono registration mode: keep partner only if email and phone matches;
|
||||
# otherwise registration > partner. Note that _phone_format has to be
|
||||
# taken into account as it may have side effects on phone formatting
|
||||
# otherwise registration > partner. Note that email format has to be
|
||||
# taken into account in comparison
|
||||
if len(self) == 1 and valid_partner:
|
||||
if self.email and valid_partner.email and valid_partner.email != self.email:
|
||||
# compare emails: email_normalized or raw
|
||||
if self.email and valid_partner.email:
|
||||
if valid_partner.email_normalized and tools.email_normalize(self.email) != valid_partner.email_normalized:
|
||||
valid_partner = self.env['res.partner']
|
||||
elif not valid_partner.email_normalized and valid_partner.email != self.email:
|
||||
valid_partner = self.env['res.partner']
|
||||
|
||||
# compare phone
|
||||
if valid_partner and valid_partner.phone and self.phone and valid_partner.phone != self.phone:
|
||||
valid_partner = self.env['res.partner']
|
||||
if valid_partner and self.phone and valid_partner.phone:
|
||||
phone_formatted = phone_validation.phone_format(
|
||||
|
||||
@@ -142,7 +142,7 @@ class TestEventCrmFlow(TestEventCrmCommon):
|
||||
})
|
||||
for email, phone, base_partner, expected_partner in [
|
||||
(False, False, self.event_customer, self.event_customer), # should take partner info
|
||||
('"Other Name" <constantin@test.example.com>', False, self.event_customer, self.env['res.partner']), # same email normalized -> currently not supported
|
||||
('"Other Name" <constantin@test.example.com>', False, self.event_customer, self.event_customer), # same email normalized
|
||||
('other.email@test.example.com', False, self.event_customer, self.env['res.partner']), # not same email -> no partner on lead
|
||||
(False, '+32485112233', self.event_customer, self.env['res.partner']), # same phone but differently formatted -> currently not supported
|
||||
(False, '0485112244', self.event_customer, self.env['res.partner']), # other phone -> no partner on lead
|
||||
|
||||
Reference in New Issue
Block a user