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.

2

How to search for several words in products name from sales order?

By
Kitti Upariphutthiphong
on 4/1/13, 9:16 AM 3,246 views

Hello,

Is it possible to implement a very flexible (almost like fulltext) search for, i.e., Products in Lines.

The intention of this is for the user to as quickly as possible find the product (during new lines and not using the search view), which they might not even know the exact name, not even order of it, they just know part of the keywords.

For example, given the product name like, "Panel / White Color / 50x40".

I am looking for the way to enhance the product fields (in Order Line), so user can just type "50x40 white" to match the item. It is almost like google search to me.

Many thanks, Kitti U.

2

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 4/1/13, 10:28 AM

I think that you are looking for the name_search function. This function is used for the search in many2one fields. This is for example the Product in the Order Line. You can override this function to fulfill you requirements.

As an example look at the name_search function of the Product (product.product).

def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100):
    if not args:
        args = []
    if name:
        ids = self.search(cr, user, [('default_code','=',name)]+ args, limit=limit, context=context)
        if not ids:
            ids = self.search(cr, user, [('ean13','=',name)]+ args, limit=limit, context=context)
        if not ids:
            # Do not merge the 2 next lines into one single search, SQL search performance would be abysmal
            # on a database with thousands of matching products, due to the huge merge+unique needed for the
            # OR operator (and given the fact that the 'name' lookup results come from the ir.translation table
            # Performing a quick memory merge of ids in Python will give much better performance
            ids = set()
            ids.update(self.search(cr, user, args + [('default_code',operator,name)], limit=limit, context=context))
            if not limit or len(ids) < limit:
                # we may underrun the limit because of dupes in the results, that's fine
                ids.update(self.search(cr, user, args + [('name',operator,name)], limit=(limit and (limit-len(ids)) or False) , context=context))
            ids = list(ids)
        if not ids:
            ptrn = re.compile('(\[(.*?)\])')
            res = ptrn.search(name)
            if res:
                ids = self.search(cr, user, [('default_code','=', res.group(2))] + args, limit=limit, context=context)
    else:
        ids = self.search(cr, user, args, limit=limit, context=context)
    result = self.name_get(cr, user, ids, context=context)
    return result

Hello Andreas. Yes I think this is what I am looking for. Thank you so much!

Ecosoft Co. LTD, Kitti Upariphutthiphong
on 4/1/13, 10:35 AM
2

Fabien Pinckaers (fp)

--Fabien Pinckaers (fp)--
6598
| 6 8 8
fsdsdfsdf, Belgium
--Fabien Pinckaers (fp)--

Odoo Founder & CEO

Fabien Pinckaers (fp)
On 4/1/13, 9:27 AM

By default, in the search view, if you do 2 searches on the same field (e.g. "Panel" & "White"), OpenERP will apply a OR condition between both. This would result into: Product contain Panel OR product contain "White". So, this will not work for your example.

To do a AND between two criteria of the same field, you can use the advanced search.

For your example, if you are in the Sales Orders or Quotations, you can do this through applying two advanced searches:

Order Lines contains Panel
Order Lines contains White

Do not add conditions within the same advanced search, you must apply two searches.

Note that it will match Panel and White, regardless of the order.

0

Thanks Fabian for the quick answer. But i think it is not exactly what I am looking for.

The intention of the question is for the user to as quickly as possible find the product (during new lines and not using the search view), which they might not even know the exact name, not even order of it, they just know part of the keywords.

Says, there are huge amount of products. And what they want to find is the one named, "Panel - White Color - 40x40".

I am looking for the way to enhance the product fields (in Order Line), so user can just type "40x40 white" to match the item. It is almost like google search to me.

Sorry if my question is not clear. But this is something many customer wanted (especially, organization with a lot of products)

Thank you, Kitti

please edit your question for clarification instead of adding an answer

Fabien Pinckaers (fp)
on 4/1/13, 11:05 AM
0
filsystem
On 4/1/13, 9:55 AM

In search field name from product list (tree) or in field product_id from order line (form) you can use regular sql LIKE expression with wildcard: 'Panel%White%50x40'. You will receive all product with 'Panel' or 'White' or '50x40' in name.

What if I need it to search in other fields than the name ?

Mahmoud Korayem
on 11/22/14, 11:46 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

2 follower(s)

Stats

Asked: 4/1/13, 9:16 AM
Seen: 3246 times
Last updated: 9/24/15, 2:10 AM