Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Select customer by Reference in Sale Order

By
Faheem Khan
on 9/30/14, 3:32 PM 886 views

I have 1200 Customers and many of them have a same name. I want to select customer by his internal reference in quotation or sale order. Any Help will be greatly appriciated? 

any help?

Faheem Khan
on 10/18/14, 7:27 AM
0

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 10/22/14, 2:04 AM

Sure you can do it...

Write a "name_search" method in the partner object...

In that you can define it to search the records based on whatever columns you want to search..

In my requirement: I have defined it such a way, that a customer can be searched using a mobile number or email or name or ref..

 

A sample code:


    def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
        if not args:
            args = []
        ids = []
        if name and operator in ('=', 'ilike', '=ilike', 'like', '=like'):
            search_name = name
            if operator in ('ilike', 'like'):
                search_name = '%%%s%%' % name  
            if operator in ('=ilike', '=like'):
                operator = operator[1:]
            query_args = {'name': search_name}
            limit_str = ''
            if limit:
                limit_str = ' limit %(limit)s'
                query_args['limit'] = limit
            search_name = query_args['name']
            cr.execute("SELECT p.id FROM res_partner p WHERE (p.name ilike '" + (search_name or '') + "%') OR (p.ref ilike '" + (search_name or '') + "%') OR (p.mobile ilike '" + (search_name or '') + "%')  OR (p.email ilike '" + (search_name or '') + "%')  ")

            ids = map(lambda x: x[0], cr.fetchall())
            ids = self.search(cr, uid, [('id', 'in', ids)] + args, limit=limit, context=context)
            if ids:
                return self.name_get(cr, uid, ids, context)
        return super(res_partner, self).name_search(cr, uid, name, args, operator=operator, context=context, limit=limit)

Thanks for your reply. Can you please show me some example?

Faheem Khan
on 10/22/14, 4:44 AM

def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100): if not args: args = [] ids = [] if name and operator in ('=', 'ilike', '=ilike', 'like', '=like'): search_name = name if operator in ('ilike', 'like'): search_name = '%%%s%%' % name if operator in ('=ilike', '=like'): operator = operator[1:] query_args = {'name': search_name} limit_str = '' if limit: limit_str = ' limit %(limit)s' query_args['limit'] = limit search_name = query_args['name'] cr.execute("SELECT p.id FROM res_partner p WHERE (p.name ilike '" + (search_name or '') + "%') OR (p.ref ilike '" + (search_name or '') + "%') OR (p.mobile ilike '" + (search_name or '') + "%') OR (p.email ilike '" + (search_name or '') + "%') OR (p.phone ilike '" + (search_name or '') + "%') ") ids = map(lambda x: x[0], cr.fetchall()) ids = self.search(cr, uid, [('id', 'in', ids)] + args, limit=limit, context=context) if ids: return self.name_get(cr, uid, ids, context) return super(res_partner, self).name_search(cr, uid, name, args, operator=operator, context=context, limit=limit)

deep
on 10/22/14, 5:47 AM

In this comment section: I couldn't align it... hence edited the above answer, and the sample code...

deep
on 10/22/14, 5:51 AM

Thanks for your brief explanation and code snipe. A littler more help bcz I am totally a newbie and not have much coding experience. This "Write a "name_search" method in the partner object..." sentence ask me to edit partner object. Where can I found partner object. In some module or in developer mode. Thanks in advance.

Faheem Khan
on 10/31/14, 7:54 AM

Can you please provide me some more help. You say that I should write a search method in partner object. My question is where I can locate this partner object in sales module. I also want to know that is this code snippet work in quotation, and purchase orders also. Or please give me some idea that how can i use this code to build a custom module for example a module with this name enhance_customer_search and install this module to gain this feature.

Faheem Khan
on 11/18/14, 12:21 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/30/14, 3:32 PM
Seen: 886 times
Last updated: 3/16/15, 8:10 AM