summaryrefslogtreecommitdiff
path: root/addons/product/tests
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-11-16 19:30:20 +0100
committerChristophe Simonis <chs@odoo.com>2018-11-16 19:30:20 +0100
commit6faad524cf5e4db02855cb213277c40aee14c42a (patch)
tree383c984dc1461a03481baa9fbdce8c156ca97e2e /addons/product/tests
parent3657dc77c2ddb4275f07d1271b93e7f25e09913a (diff)
parentbc744a1da46efda6f1eb5c341f2fa5df30c9c7ad (diff)
[MERGE] forward port branch 12.0 up to bc744a1da46
Diffstat (limited to 'addons/product/tests')
-rw-r--r--addons/product/tests/common.py16
-rw-r--r--addons/product/tests/test_variants.py94
2 files changed, 110 insertions, 0 deletions
diff --git a/addons/product/tests/common.py b/addons/product/tests/common.py
index 559b8b9dcfa..50831e2a88c 100644
--- a/addons/product/tests/common.py
+++ b/addons/product/tests/common.py
@@ -101,3 +101,19 @@ class TestProductCommon(common.SavepointCase):
'name': 'Stone',
'uom_id': cls.uom_unit.id,
'uom_po_id': cls.uom_unit.id})
+
+
+class TestAttributesCommon(common.SavepointCase):
+
+ @classmethod
+ def setUpClass(cls):
+ super(TestAttributesCommon, cls).setUpClass()
+
+ # create 10 attributes with 10 values each
+ cls.att_names = "ABCDEFGHIJ"
+ cls.attributes = cls.env['product.attribute'].create([{
+ 'name': name,
+ 'create_variant': 'no_variant',
+ 'value_ids': [(0, 0, {'name': n}) for n in range(10)]
+ } for name in cls.att_names
+ ])
diff --git a/addons/product/tests/test_variants.py b/addons/product/tests/test_variants.py
index 8fc890c31f1..9381868b623 100644
--- a/addons/product/tests/test_variants.py
+++ b/addons/product/tests/test_variants.py
@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import common
+from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase
class TestVariantsSearch(TransactionCase):
@@ -367,3 +368,96 @@ class TestVariantsNoCreate(common.TestProductCommon):
variant_id.attribute_value_ids += self.size_S
template.attribute_line_ids += template.attribute_line_ids.browse()
self.assertEqual(len(template.product_variant_ids), 1)
+
+
+class TestVariantsManyAttributes(common.TestAttributesCommon):
+
+ def test_01_create_no_variant(self):
+ toto = self.env['product.template'].create({
+ 'name': 'Toto',
+ 'attribute_line_ids': [(0, 0, {
+ 'attribute_id': attribute.id,
+ 'value_ids': [(6, 0, attribute.value_ids.ids)],
+ }) for attribute in self.attributes],
+ })
+ self.assertEqual(len(toto.attribute_line_ids.mapped('attribute_id')), 10)
+ self.assertEqual(len(toto.attribute_line_ids.mapped('value_ids')), 100)
+ self.assertEqual(len(toto.product_variant_ids), 1)
+
+ def test_02_create_dynamic(self):
+ self.attributes.write({'create_variant': 'dynamic'})
+ toto = self.env['product.template'].create({
+ 'name': 'Toto',
+ 'attribute_line_ids': [(0, 0, {
+ 'attribute_id': attribute.id,
+ 'value_ids': [(6, 0, attribute.value_ids.ids)],
+ }) for attribute in self.attributes],
+ })
+ self.assertEqual(len(toto.attribute_line_ids.mapped('attribute_id')), 10)
+ self.assertEqual(len(toto.attribute_line_ids.mapped('value_ids')), 100)
+ self.assertEqual(len(toto.product_variant_ids), 0)
+
+ def test_03_create_always(self):
+ self.attributes.write({'create_variant': 'always'})
+ with self.assertRaises(UserError):
+ self.env['product.template'].create({
+ 'name': 'Toto',
+ 'attribute_line_ids': [(0, 0, {
+ 'attribute_id': attribute.id,
+ 'value_ids': [(6, 0, attribute.value_ids.ids)],
+ }) for attribute in self.attributes],
+ })
+
+ def test_04_create_no_variant_dynamic(self):
+ self.attributes[:5].write({'create_variant': 'dynamic'})
+ toto = self.env['product.template'].create({
+ 'name': 'Toto',
+ 'attribute_line_ids': [(0, 0, {
+ 'attribute_id': attribute.id,
+ 'value_ids': [(6, 0, attribute.value_ids.ids)],
+ }) for attribute in self.attributes],
+ })
+ self.assertEqual(len(toto.attribute_line_ids.mapped('attribute_id')), 10)
+ self.assertEqual(len(toto.attribute_line_ids.mapped('value_ids')), 100)
+ self.assertEqual(len(toto.product_variant_ids), 0)
+
+ def test_05_create_no_variant_always(self):
+ self.attributes[:2].write({'create_variant': 'always'})
+ toto = self.env['product.template'].create({
+ 'name': 'Toto',
+ 'attribute_line_ids': [(0, 0, {
+ 'attribute_id': attribute.id,
+ 'value_ids': [(6, 0, attribute.value_ids.ids)],
+ }) for attribute in self.attributes],
+ })
+ self.assertEqual(len(toto.attribute_line_ids.mapped('attribute_id')), 10)
+ self.assertEqual(len(toto.attribute_line_ids.mapped('value_ids')), 100)
+ self.assertEqual(len(toto.product_variant_ids), 100)
+
+ def test_06_create_dynamic_always(self):
+ self.attributes[:5].write({'create_variant': 'dynamic'})
+ self.attributes[5:].write({'create_variant': 'always'})
+ toto = self.env['product.template'].create({
+ 'name': 'Toto',
+ 'attribute_line_ids': [(0, 0, {
+ 'attribute_id': attribute.id,
+ 'value_ids': [(6, 0, attribute.value_ids.ids)],
+ }) for attribute in self.attributes],
+ })
+ self.assertEqual(len(toto.attribute_line_ids.mapped('attribute_id')), 10)
+ self.assertEqual(len(toto.attribute_line_ids.mapped('value_ids')), 100)
+ self.assertEqual(len(toto.product_variant_ids), 0)
+
+ def test_07_create_no_create_dynamic_always(self):
+ self.attributes[3:6].write({'create_variant': 'dynamic'})
+ self.attributes[6:].write({'create_variant': 'always'})
+ toto = self.env['product.template'].create({
+ 'name': 'Toto',
+ 'attribute_line_ids': [(0, 0, {
+ 'attribute_id': attribute.id,
+ 'value_ids': [(6, 0, attribute.value_ids.ids)],
+ }) for attribute in self.attributes],
+ })
+ self.assertEqual(len(toto.attribute_line_ids.mapped('attribute_id')), 10)
+ self.assertEqual(len(toto.attribute_line_ids.mapped('value_ids')), 100)
+ self.assertEqual(len(toto.product_variant_ids), 0)