Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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.
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 (
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
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.
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 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 platform 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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 4/1/13, 9:16 AM|
|Seen: 3380 times|
|Last updated: 9/24/15, 2:10 AM|