From 99bae2cdb794051a931fac0b0ac53f2915fd3032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Warnon?= Date: Tue, 23 Oct 2018 08:47:05 +0000 Subject: [PATCH] [FIX] product: fix _name_search to include dynamic product variants Targets commit d3530eb07e24278117ab396ecb86a59deecc312d 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 --- addons/product/models/product_template.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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