Skip to Content
Menu
This question has been flagged
2 Replies
3787 Views

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)



Avatar
Discard
Best Answer

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.

Avatar
Discard
Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
1
May 25
522
1
Apr 25
878
1
Mar 25
758
1
Feb 25
1041
2
Feb 25
1128