summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2019-08-29 08:25:18 +0000
committerLucas Perais (lpe) <lpe@odoo.com>2019-08-29 10:19:47 +0000
commit21ae503cf401afe4dddae6225fd346f89a210aeb (patch)
tree316bcfa6a9cbf7feb1e2ad874961da76bda10bd2
parent3950702c86733f52fb373d55a0898baf593de239 (diff)
[FIX] product: name search on dynamic product template
Have a product template, assign a dynamic attribute to (the corresponding variant will be created when used in a SO) Try to name_search for it e.g.: in the product configurator modal, type some letters to catch it in theory Before this commit, the product template was not found by the name search this is because the template doesn't have any variant yet After this commit, it is found by the name search OPW 2060603 closes odoo/odoo#36215 Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
-rw-r--r--addons/product/models/product_template.py9
-rw-r--r--addons/product/tests/test_variants.py22
2 files changed, 30 insertions, 1 deletions
diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py
index 1b219a179e3..24c3c44bd44 100644
--- a/addons/product/models/product_template.py
+++ b/addons/product/models/product_template.py
@@ -407,13 +407,20 @@ class ProductTemplate(models.Model):
Product = self.env['product.product']
templates = self.browse([])
+ domain_no_variant = [('product_variant_ids', '=', False)]
while True:
domain = templates and [('product_tmpl_id', 'not in', templates.ids)] or []
args = args if args is not None else []
products_ns = Product._name_search(name, args+domain, operator=operator, name_get_uid=name_get_uid)
products = Product.browse([x[0] for x in products_ns])
templates |= products.mapped('product_tmpl_id')
- if (not products) or (limit and (len(templates) > limit)):
+ current_round_templates = self.browse([])
+ if not products:
+ domain_template = args + domain_no_variant + (templates and [('id', 'not in', templates.ids)] or [])
+ template_ns = super(ProductTemplate, self)._name_search(name=name, args=domain_template, operator=operator, limit=limit, name_get_uid=name_get_uid)
+ current_round_templates |= self.browse([ns[0] for ns in template_ns])
+ templates |= current_round_templates
+ if (not products and not current_round_templates) or (limit and (len(templates) > limit)):
break
# re-apply product.template order + name_get
diff --git a/addons/product/tests/test_variants.py b/addons/product/tests/test_variants.py
index 251996a2526..97323a0cee3 100644
--- a/addons/product/tests/test_variants.py
+++ b/addons/product/tests/test_variants.py
@@ -817,3 +817,25 @@ class TestVariantsArchive(common.TestProductCommon):
"We should have re-activated one variant only.")
Product._revert_method('unlink')
+
+ def test_name_search_dynamic_attributes(self):
+ dynamic_attr = self.env['product.attribute'].create({
+ 'name': 'Dynamic',
+ 'create_variant': 'dynamic',
+ 'value_ids': [(0, False, {'name': 'ValueDynamic'})],
+ })
+ template = self.env['product.template'].create({
+ 'name': 'cimanyd'
+ })
+ self.assertEqual(len(template.product_variant_ids), 1)
+
+ template.write({
+ 'attribute_line_ids': [(0, False, {
+ 'attribute_id': dynamic_attr.id,
+ 'value_ids': [(4, dynamic_attr.value_ids[0].id, False)],
+ })]
+ })
+ self.assertEqual(len(template.product_variant_ids), 0)
+
+ name_searched = self.env['product.template'].name_search(name='cima')
+ self.assertIn(template.id, [ng[0] for ng in name_searched])