summaryrefslogtreecommitdiff
path: root/addons/crm/models
diff options
context:
space:
mode:
authorijas ahammed <ija@odoo.com>2020-11-26 11:31:52 +0000
committerThibault Delavallée <tde@odoo.com>2020-12-17 09:10:41 +0000
commit5154f40544e7913f7bcd0ff73f034d111700f580 (patch)
tree96399e5eecab3b1a699d1c889d814da745b7ecdc /addons/crm/models
parent9b3c4d07b3832bf99c6a9603985b687124fed033 (diff)
[FIX] crm: do not propagate lead phone to partner if formatting differs
With a recent commit[1], we fixed the issue of false warning while changing the partner on lead. But that fix ignored the fact that the lead has an automatic formatting that may lead to false warning. Right way to detect a phone number change is * lead phone is different from partner phone; * lead formatted phone is different from partner formatted phone; If those two conditions are met we are quite sure numbers are different and not only differs in their formatting. In this commit we also fix inverse of phone number. When updating lead phone value we have to use the same heuristic to update partner phone value. That was we avoid unnecessary partner update when only formatting differs. Tests are added to ensure new behavior and that ribbon message is effectively trig erred with correct content. LINKS Task ID-2390287 [1] - https://github.com/odoo/odoo/commit/d29862c1de6208f7fdb7c8104afe0d35241d130b closes odoo/odoo#62397 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Co-authored-by: Ijas Ahammed <ija@odoo.com> Co-authored-by: Thibault Delavallée <tde@odoo.com>
Diffstat (limited to 'addons/crm/models')
-rw-r--r--addons/crm/models/crm_lead.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py
index c07b27c8c3e..1ee22437bda 100644
--- a/addons/crm/models/crm_lead.py
+++ b/addons/crm/models/crm_lead.py
@@ -325,7 +325,15 @@ class Lead(models.Model):
def _inverse_phone(self):
for lead in self:
if lead.partner_id and lead.phone != lead.partner_id.phone:
- lead.partner_id.phone = lead.phone
+ # force reset
+ if not lead.phone or not lead.partner_id.phone:
+ lead.partner_id.phone = lead.phone
+ # compare formatted values as we may have encoding differences between equivalent numbers
+ else:
+ lead_phone_formatted = lead.phone_format(lead.phone)
+ partner_phone_formatted = lead.phone_format(lead.partner_id.phone)
+ if lead_phone_formatted != partner_phone_formatted:
+ lead.partner_id.phone = lead.phone
@api.depends('phone', 'country_id.code')
def _compute_phone_state(self):
@@ -398,9 +406,18 @@ class Lead(models.Model):
@api.depends('email_from', 'phone', 'partner_id')
def _compute_ribbon_message(self):
for lead in self:
- partner_formatted_phone = lead.partner_id.phone and self.phone_format(lead.partner_id.phone)
will_write_email = lead.partner_id and lead.email_from != lead.partner_id.email
- will_write_phone = lead.partner_id and lead.phone != partner_formatted_phone
+ will_write_phone = False
+ if lead.partner_id and lead.phone != lead.partner_id.phone:
+ # if reset -> obviously new value will be propagated
+ if not lead.phone or not lead.partner_id.phone:
+ will_write_phone = True
+ # otherwise compare formatted values as we may have encoding differences
+ else:
+ lead_phone_formatted = lead.phone_format(lead.phone)
+ partner_phone_formatted = lead.phone_format(lead.partner_id.phone)
+ if lead_phone_formatted != partner_phone_formatted:
+ will_write_phone = True
if will_write_email and will_write_phone:
lead.ribbon_message = _('By saving this change, the customer email and phone number will also be updated.')