From b08ea4414f4e2eefcc9e71ca7e876d2cd44c7565 Mon Sep 17 00:00:00 2001 From: Julien Banken Date: Fri, 23 Apr 2021 13:18:58 +0000 Subject: [FIX] crm: fix incorrect prefix removal from phone filter When the user searches a phone number, the search function will generate a pattern by removing the "+" sign as well as well as the prefix "00" from the input string. Problem: If the input string starts with "+", it means that the phone number will be prefixed by something different than "00". As the function will systematically remove the first occurrence of "00" from the input string, the function can remove part of the input string that does not correspond to a prefix. The search results can hence be incorrect. Example: If the user types "+32485001122", the function will remove the "+" sign and the first occurrence of "00" from the input string. In the provided example, the function will search phone numbers matching with the pattern "324851122" which is incorrect. Solution: The function should remove the first occurrence of "00" iff the phone starts with "00". Task id: 2479277 COM PR: odoo/odoo#69729 Signed-off-by: Thibault Delavallee (tde) --- addons/crm/models/crm_lead.py | 3 ++- addons/crm/tests/test_crm_lead.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'addons/crm') diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 37cdf2a0cb7..03127b46899 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -493,7 +493,8 @@ class Lead(models.Model): # searching on +32485112233 should also finds 00485112233 (00 / + prefix are both valid) # we therefore remove it from input value and search for both of them in db if value.startswith('+') or value.startswith('00'): - value = value.replace('+', '').replace('00', '', 1) + if value.startswith('00'): + value = value[2:] starts_with = '00|\+' else: starts_with = '%' diff --git a/addons/crm/tests/test_crm_lead.py b/addons/crm/tests/test_crm_lead.py index fdd5aadce12..119f356a251 100644 --- a/addons/crm/tests/test_crm_lead.py +++ b/addons/crm/tests/test_crm_lead.py @@ -386,3 +386,19 @@ class TestCRMLead(TestCrmCommon): new_lead.handle_partner_assignment(create_missing=True) self.assertEqual(new_lead.partner_id.email, 'unknown.sender@test.example.com') self.assertEqual(new_lead.partner_id.team_id, self.sales_team_1) + + @users('user_sales_manager') + def test_phone_mobile_search(self): + lead_1 = self.env['crm.lead'].create({ + 'name': 'Lead 1', + 'country_id': self.env.ref('base.be').id, + 'phone': '+32485001122', + }) + lead_2 = self.env['crm.lead'].create({ + 'name': 'Lead 2', + 'country_id': self.env.ref('base.be').id, + 'phone': '+32485112233', + }) + self.assertEqual(lead_1, self.env['crm.lead'].search([ + ('phone_mobile_search', 'like', '+32485001122') + ])) -- cgit v1.2.3