[FIX] product: fix _name_search to include dynamic product variants

Targets commit d3530eb07e

Purpose
=======
- The _name_search of product.template fallbacks by default on product.product
  In case there are no product.products yet (dynamic product variants configuration), we need to
  include the base product.template _name_search in the results
This commit is contained in:
Aurélien Warnon
2019-03-18 13:41:33 +00:00
parent ec88b4e1a2
commit 99bae2cdb7
+15 -1
View File
@@ -406,9 +406,23 @@ class ProductTemplate(models.Model):
if (not products) or (limit and (len(templates) > limit)):
break
searched_ids = set(templates.ids)
# some product.templates do not have product.products yet (dynamic variants configuration),
# we need to add the base _name_search to the results
# FIXME awa: this is really not performant at all but after discussing with the team
# we don't see another way to do it
if len(searched_ids) < limit:
searched_ids |= set([template_id[0] for template_id in
super(ProductTemplate, self)._name_search(
name,
args=args,
operator=operator,
limit=limit,
name_get_uid=name_get_uid)])
# re-apply product.template order + name_get
return super(ProductTemplate, self)._name_search(
'', args=[('id', 'in', list(set(templates.ids)))],
'', args=[('id', 'in', list(searched_ids))],
operator='ilike', limit=limit, name_get_uid=name_get_uid)
@api.multi