Skip to content

Commit

Permalink
[FIX] product: fix _name_search to include dynamic product variants
Browse files Browse the repository at this point in the history
Targets commit d3530eb

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
  • Loading branch information
awa-odoo committed Mar 18, 2019
1 parent 69b503f commit a03e623
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion addons/product/models/product_template.py
Expand Up @@ -381,9 +381,23 @@ def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_ui
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
Expand Down

0 comments on commit a03e623

Please sign in to comment.