From 4b6309f5ded42ccfa6f7f09c39b26473abc9334d Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 26 Aug 2015 10:18:40 +0200 Subject: [PATCH] [FIX] product: name_search result The function "name_search" defined on "product.template" made a search on "product.product" name to give the "product.template" which matched with the search. The number of results given by the name_search on "product.product" is generally limited to 8. The problem was when for example there were 8 variants ("product.product") with a name begining by "AA" for the same "product.template" T1 and another "product.product" with a name begining by "AB" linked to T2. In this situation, if a name_search was made on "product.template" with a name="A", the result got was just the the name of T1 linked to the 8 variants instead of the name of the two templates (T1 and T2) due to the limitation. opw:647066 --- addons/product/product.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index 1e4d73c58e1..45074b0e299 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -821,18 +821,24 @@ class product_template(osv.osv): if not name or any(term[0] == 'id' for term in (args or [])): return super(product_template, self).name_search( cr, user, name=name, args=args, operator=operator, context=context, limit=limit) - + template_ids = set() product_product = self.pool['product.product'] - results = product_product.name_search( - cr, user, name, args, operator=operator, context=context, limit=limit) + results = product_product.name_search(cr, user, name, args, operator=operator, context=context, limit=limit) product_ids = [p[0] for p in results] - template_ids = [p.product_tmpl_id.id - for p in product_product.browse( - cr, user, product_ids, context=context)] + for p in product_product.browse(cr, user, product_ids, context=context): + template_ids.add(p.product_tmpl_id.id) + while (results and len(template_ids) < limit): + domain = [('product_tmpl_id', 'not in', list(template_ids))] + results = product_product.name_search( + cr, user, name, args+domain, operator=operator, context=context, limit=limit) + product_ids = [p[0] for p in results] + for p in product_product.browse(cr, user, product_ids, context=context): + template_ids.add(p.product_tmpl_id.id) + # re-apply product.template order + name_get return super(product_template, self).name_search( - cr, user, '', args=[('id', 'in', template_ids)], + cr, user, '', args=[('id', 'in', list(template_ids))], operator='ilike', context=context, limit=limit) class product_product(osv.osv):