تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
4029 أدوات العرض

Hello,


I am using a custom module that allows you to search for partners by Mobile Number.

The module works perfectly. However, I have to search for the numbers including all the spaces.

For example:
Number: +20 110 155 1516

Search Attempt (Failed):

 +201101551516


I want to be able to search for the number without any spaces included.


The Code:

from odoo import models, api,_
from odoo.exceptions import ValidationError, AccessError

class ResPartner(models.Model):
    _inherit = 'res.partner'

    @api.model
    def name_search(self, name='', args=None, operator='ilike', limit=100):
        """ This method will find Customer names according to their mobile,
        phone, city, email and its job position."""
        if name and not self.env.context.get('import_file'):
            #name.replace(" ","")
            #name = [i.replace(",", "") for i in name]
            
            args = args if args else []
            args.extend(['|', ['name', 'ilike', name],
                         '|', ['mobile', 'ilike', name],
                         '|', ['city', 'ilike', name],
                         '|', ['email', 'ilike', name],
                         '|', ['phone', 'ilike', name],
                         ['function', 'ilike', name]])
            name = ''
        return super(ResPartner, self).name_search(
            name=name, args=args, operator=operator, limit=limit)



الصورة الرمزية
إهمال
أفضل إجابة

One way would be to define a computed field that stores the phone number without spaces and use the computed field in your domain definition.

الصورة الرمزية
إهمال
أفضل إجابة

did you find a solution to this problem? I also have the same problem as you, thank you

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يونيو 25
1711
1
مايو 25
979
1
مارس 25
1205
MERGING CONTACTS تم الحل
1
فبراير 25
1591
Use of external id تم الحل
2
فبراير 25
2139