Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit 28b6cf4

Browse files
Richard deMeesterPCatinean
authored andcommitted
Create Variant Ids loop cleanup and test.
1 parent 3901781 commit 28b6cf4

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

product_configurator/models/product.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,10 @@ def name_search(self, name='', args=None, operator='ilike', limit=100):
472472
def create_variant_ids(self):
473473
""" Prevent configurable products from creating variants as these serve
474474
only as a template for the product configurator"""
475-
for product in self:
476-
if self.config_ok:
477-
return None
478-
return super(ProductTemplate, self).create_variant_ids()
475+
templates = self.filtered(lambda t: not t.config_ok)
476+
if not templates:
477+
return None
478+
return super(ProductTemplate, templates).create_variant_ids()
479479

480480
@api.multi
481481
def unlink(self):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
from . import test_configuration_rules
3+
from . import test_configuration_rules, test_create
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from odoo.tests.common import TransactionCase
4+
5+
6+
class ConfigurationCreate(TransactionCase):
7+
8+
def test_create(self):
9+
"""Test configuration item does not make variations"""
10+
11+
attr_test = self.env['product.attribute'].create(
12+
{'name': 'Test',
13+
'value_ids': [
14+
(0, 0, {'name': '1'}),
15+
(0, 0, {'name': '2'}),
16+
],
17+
}
18+
)
19+
test_template = self.env['product.template'].create(
20+
{'name': 'Test Configuration',
21+
'config_ok': True,
22+
'type': 'product',
23+
'categ_id': self.env['ir.model.data'].xmlid_to_res_id(
24+
'product.product_category_5'
25+
),
26+
'attribute_line_ids': [
27+
(0, 0, {'attribute_id': attr_test.id,
28+
'value_ids': [
29+
(6, 0, attr_test.value_ids.ids),
30+
],
31+
'required': True,
32+
}),
33+
]
34+
}
35+
)
36+
37+
self.assertEqual(
38+
test_template.product_variant_count,
39+
0,
40+
"Create should not have any variants"
41+
)
42+

0 commit comments

Comments
 (0)