Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] product_variant_configurator: allow force variant creation #397

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions product_variant_configurator/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def _create_variant_ids(self):
)
or tmpl.no_create_variants == "no"
or not tmpl.attribute_line_ids
or self.env.context.get("force_create_variants", False)
):
super(ProductTemplate, tmpl)._create_variant_ids()
return True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,44 @@ def test_no_create_variants_category(self):
# default behavior: one variant should be created
self.assertEqual(len(tmpl.product_variant_ids), 1)

def test_no_create_variants_force(self):
tmpl = self.product_template.create(
{
"name": "No create variants template",
"no_create_variants": "yes",
"attribute_line_ids": [
(
0,
0,
{
"attribute_id": self.attribute1.id,
"value_ids": [(6, 0, [self.value1.id, self.value2.id])],
},
)
],
}
)
self.assertEqual(len(tmpl.product_variant_ids), 0)
# We create a product identical to the last one, but
# we force the creation of variants with the context
tmpl = self.product_template.with_context(force_create_variants=True).create(
{
"name": "No create variants template",
"no_create_variants": "yes",
"attribute_line_ids": [
(
0,
0,
{
"attribute_id": self.attribute1.id,
"value_ids": [(6, 0, [self.value1.id, self.value2.id])],
},
)
],
}
)
self.assertEqual(len(tmpl.product_variant_ids), 2)

def test_create_variants(self):
tmpl = self.product_template.create(
{
Expand Down