From b89f948ef4789ec8dc400ef8c8e40778d5bbe406 Mon Sep 17 00:00:00 2001
From: niyasraphy <niyasraphyk@gmail.com>
Date: Wed, 24 May 2023 09:40:13 +0000
Subject: [PATCH] [REF] phone_validation: class attribute to bypass the length
 validation

before this commit, if user need to bypass the validation
added for the length in custom module, the entire function
has be rewritten in the custom module.

scenario:

* add the phone_mobile_search field to the name search of res.partner model

* then open sale order form, and in the customer field enter any letter or digits, this user
error will be raised

after this commit, users just need to change the class
attribute: _phone_search_min_length in the
inherited module.

closes odoo/odoo#122248

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
---
 addons/phone_validation/models/mail_thread_phone.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/addons/phone_validation/models/mail_thread_phone.py b/addons/phone_validation/models/mail_thread_phone.py
index 059eeb399f2a..4d7a48acd5e3 100644
--- a/addons/phone_validation/models/mail_thread_phone.py
+++ b/addons/phone_validation/models/mail_thread_phone.py
@@ -29,6 +29,7 @@ class PhoneMixin(models.AbstractModel):
     _name = 'mail.thread.phone'
     _description = 'Phone Blacklist Mixin'
     _inherit = ['mail.thread']
+    _phone_search_min_length = 3
 
     phone_sanitized = fields.Char(
         string='Sanitized Number', compute="_compute_phone_sanitized", compute_sudo=True, store=True,
@@ -64,7 +65,7 @@ class PhoneMixin(models.AbstractModel):
             op = expression.AND if operator == '=' else expression.OR
             return op([[(phone_field, operator, False)] for phone_field in phone_fields])
 
-        if len(value) < 3:
+        if self._phone_search_min_length and len(value) < self._phone_search_min_length:
             raise UserError(_('Please enter at least 3 characters when searching a Phone/Mobile number.'))
 
         pattern = r'[\s\\./\(\)\-]'
-- 
GitLab