Skip to Content
Menu
This question has been flagged
3 Replies
6249 Views

Hi,

I would like to select a customer from the select box by start typing its phone number.
How can I do that?
I have seen that we can use name_search method how to use it, both back end and frond end ?
Is anyone know this?

Thanks in advance.


Avatar
Discard
Best Answer

Hi Silpa,

You can achieve it using a combination of _rec_name,name_search and name_get methods as follows:

1. You need to define _rec_name like:

_rec_name = 'mobile'

2. Need to override name_search as:

def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100):

        res = super(res_partner,self).name_search(cr,user,name,args,operator,context,limit)

        if not res:

                ids = self.search(cr, user, [('mobile',operator,name)], limit=limit, context=context)

                res = self.name_get(cr, user, ids, context=context)

        return res

3. Need to override name_get as:

def name_get(self, cr, uid, ids, context=None):

        if context is None:

                context = {}

        if isinstance(ids, (int, long)):

                ids = [ids]

        res = []

        reads = self.read(cr, uid, ids, ['name', 'mobile'], context=context)

        for record in reads:

                if record['name']:

                        name = record['name']

                res.append((record['id'], name))

        return res

Avatar
Discard
Best Answer

Hi  Silpa, 

You have to use particular filter_domain in search view:

Inherit the res.partner search view and then add this line:

 <field name="phone" filter_domain="['|',('phone','ilike',self)]"/>

 


Hope This WilL Help You. Give Thumps up.!


Thanks,

ChanDni.

Avatar
Discard
Author Best Answer

Hi ChanDni,

Thank you for your answer.And what i need is to select a customer in select box or many2one field in another form.

Avatar
Discard

I am not getting what actual your requirement is. Select Customer in select box? !! and many2one field can be there in another form. What functionality you want?

Author

i have a form with many2one field(customer selection box) and if i have 2 customers with same name like 'A' so i need to search a customer with his mobile number with in that selection box.

Then you should use the name_get method. Inherit the object res.partner and overwrite the method name_get:

@api.multi

def name_get(self):

result = super(res_partner,self).name_get()

for record in self:

....

your code...

....

return .....

Related Posts Replies Views Activity
1
Dec 18
1693
2
Oct 18
6480
1
Dec 16
5558
1
Aug 16
2397
1
May 16
2162