Skip to content

Commit

Permalink
Merge PR #338 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Mar 15, 2024
2 parents afdd52d + ed1c0e2 commit 78ccb13
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
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}")

0 comments on commit 78ccb13

Please sign in to comment.