diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index d9ea1b37bc5..813f285456b 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -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