From 489a96c2572bbe2cc04c0658ed2b862aca31fc0f Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 18 Mar 2015 11:22:39 +0100 Subject: [PATCH] [FIX] product.template: name_search order + mismatch on IDs Improve commit bf31ab6718a8b9c8afdd29120e5056533b0a2ade: - do not use the product.product name_search() when there is no search term (it's only useful with a search term - do not use the product.product name_search() when the extra domain (args) has a criterion on IDs - these will be *template* ids, not *variant* ids, so the results would be wrong - Since templates and variants use a different natural `_order`, perform an extra name_search() on templates after gathering the ids to return, to apply the proper sort ordering. Increases the penalty by doing 2 name_search() calls. This issue could be seen e.g. in the breadcrumbs where the display_name variable is displayed for templates, and indirectly relies on name_search() due to an old hack in call_kw in order to implement the "future_display_name". --- addons/product/product.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index 1d02642de94..0a765623cb8 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -800,6 +800,12 @@ class product_template(osv.osv): return super(product_template, self).name_get(cr, user, ids, context) def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100): + # Only use the product.product heuristics if there is a search term and the domain + # does not specify a match on `product.template` IDs. + 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) + product_product = self.pool['product.product'] results = product_product.name_search( cr, user, name, args, operator=operator, context=context, limit=limit) @@ -807,8 +813,11 @@ class product_template(osv.osv): template_ids = [p.product_tmpl_id.id for p in product_product.browse( cr, user, product_ids, context=context)] - uniq_ids = OrderedDict.fromkeys(template_ids).keys() - return self.name_get(cr, user, uniq_ids, context=context) + + # re-apply product.template order + name_get + return super(product_template, self).name_search( + cr, user, '', args=[('id', 'in', template_ids)], + operator=operator, context=context, limit=limit) class product_product(osv.osv): _name = "product.product"