Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4027 Lượt xem

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)



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 25
1710
1
thg 5 25
977
1
thg 3 25
1203
MERGING CONTACTS Đã xử lý
1
thg 2 25
1590
Use of external id Đã xử lý
2
thg 2 25
2133