summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorJulien Banken <jbn@odoo.com>2021-04-23 13:18:58 +0000
committerJulien Banken <jbn@odoo.com>2021-04-23 13:18:58 +0000
commitb08ea4414f4e2eefcc9e71ca7e876d2cd44c7565 (patch)
treefa709c35bf19ef4be4b778ccbd33adec6fd49afb /addons
parent22cf05f652ceb1f0f2e17d160cdf8d0cc5a00a15 (diff)
[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) <tde@openerp.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/crm/models/crm_lead.py3
-rw-r--r--addons/crm/tests/test_crm_lead.py16
2 files changed, 18 insertions, 1 deletions
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')
+ ]))