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

[15.0][FIX] product_variant_default_code: recurrent prefix #338

Merged
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
8 changes: 7 additions & 1 deletion product_variant_default_code/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ def _compute_reference_mask(self):
if automask or not rec.reference_mask:
rec.reference_mask = rec._get_default_mask()
elif not automask and rec.code_prefix:
rec.reference_mask = rec.code_prefix + rec.reference_mask
reference_mask = rec.reference_mask
# Avoid prefixing the mask twice (or more).
# TODO: This needs a better design with a third field that sums both
# or using the sum of them in the variant default code computation
if reference_mask.startswith(rec.code_prefix):
reference_mask = reference_mask.lstrip(rec.code_prefix)
rec.reference_mask = rec.code_prefix + reference_mask

def _inverse_reference_mask(self):
self._compute_reference_mask()
Expand Down
30 changes: 17 additions & 13 deletions product_variant_default_code/tests/test_variant_default_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,21 @@ def test_18_both_prefix_and_mask_changing(self):
"reference_mask": "fix-[TColor]/[TSize]",
}
)

for product in self.template1.mapped("product_variant_ids"):
expected_code = (
self.template1.code_prefix
+ "fix-"
+ product.product_template_attribute_value_ids.filtered(
lambda x: x.product_attribute_value_id.attribute_id == self.attr2
).name[0:2]
+ "/"
+ product.product_template_attribute_value_ids.filtered(
lambda x: x.product_attribute_value_id.attribute_id == self.attr1
).name[0:2]
)
self.assertEqual(product.default_code, expected_code)
attr1 = product.product_template_attribute_value_ids.filtered(
lambda x: x.product_attribute_value_id.attribute_id == self.attr2
).name[0:2]
attr2 = product.product_template_attribute_value_ids.filtered(
lambda x: x.product_attribute_value_id.attribute_id == self.attr1
).name[0:2]
self.assertEqual(product.default_code, f"pre/fix-{attr1}/{attr2}")
# The reference_mask stays the same even if recomputed
self.template1._compute_reference_mask()
for product in self.template1.mapped("product_variant_ids"):
attr1 = product.product_template_attribute_value_ids.filtered(
lambda x: x.product_attribute_value_id.attribute_id == self.attr2
).name[0:2]
attr2 = product.product_template_attribute_value_ids.filtered(
lambda x: x.product_attribute_value_id.attribute_id == self.attr1
).name[0:2]
self.assertEqual(product.default_code, f"pre/fix-{attr1}/{attr2}")
Loading