Skip to content
Snippets Groups Projects
Commit 6f0de831 authored by Thibault Delavallée's avatar Thibault Delavallée
Browse files

[IMP] event_crm: compare formatted numbers when possible

Partial backport of odoo/odoo@94fa8d962535a754c9fb26997a38cc8b51b8974e keeping only event_crm part as
other changes were done only for Odoo16.

In this commit we try to compare formatted phones of registration and
partner, before checking the actual phone numbers. If only formatting
differs then it is not a different number.

Task-3431124

Part-of: odoo/odoo#128823
parent 0d37b138
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
from collections import defaultdict
from odoo import api, fields, models, tools, _
from odoo.addons.phone_validation.tools import phone_validation
class EventRegistration(models.Model):
......@@ -196,8 +197,8 @@ 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 email format has to be
# taken into account in comparison
# otherwise registration > partner. Note that email format and phone
# formatting have to taken into account in comparison
if len(self) == 1 and valid_partner:
# compare emails: email_normalized or raw
if self.email and valid_partner.email:
......@@ -206,9 +207,26 @@ class EventRegistration(models.Model):
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']
# compare phone, taking into account formatting
if valid_partner and self.phone and valid_partner.phone:
phone_formatted = phone_validation.phone_format(
self.phone,
valid_partner.country_id.code or None,
valid_partner.country_id.phone_code or None,
force_format='E164',
raise_exception=False
)
partner_phone_formatted = phone_validation.phone_format(
valid_partner.phone,
valid_partner.country_id.code or None,
valid_partner.country_id.phone_code or None,
force_format='E164',
raise_exception=False
)
if phone_formatted and partner_phone_formatted and phone_formatted != partner_phone_formatted:
valid_partner = self.env['res.partner']
if (not phone_formatted or not partner_phone_formatted) and self.phone != valid_partner.phone:
valid_partner = self.env['res.partner']
if valid_partner:
contact_vals = self.env['crm.lead']._prepare_values_from_partner(valid_partner)
......
......@@ -144,7 +144,7 @@ class TestEventCrmFlow(TestEventCrmCommon):
(False, False, self.event_customer, self.event_customer), # should take partner info
('"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, '+32485112233', self.event_customer, self.event_customer), # same phone but differently formatted
(False, '0485112244', self.event_customer, self.env['res.partner']), # other phone -> no partner on lead
('other.email@test.example.com', '0485112244', self.event_customer2, self.event_customer2), # mail / phone update from registration as void on partner
]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment