Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
4026 Näkymät

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
Hylkää
Paras vastaus

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
Hylkää
Paras vastaus

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

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
kesäk. 25
1710
1
toukok. 25
977
1
maalisk. 25
1201
1
helmik. 25
1589
2
helmik. 25
2133