[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".
This commit is contained in:
Olivier Dony 2015-03-18 11:22:39 +01:00
parent 6aa28a89bb
commit 489a96c257
1 changed files with 11 additions and 2 deletions

View File

@ -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"