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_configurator: share config restrictions #140

Draft
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Draft
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
44 changes: 17 additions & 27 deletions product_configurator/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,35 +341,25 @@ def _check_config_line_domain(self):
attribute_line_ids = self.attribute_line_ids
tmpl_value_ids = attribute_line_ids._configurator_value_ids()
tmpl_attribute_ids = attribute_line_ids.mapped("attribute_id")
error_message = False
error_message = ""
for domain_id in self.config_line_ids.mapped("domain_id"):
domain_attr_ids = domain_id.domain_line_ids.mapped("attribute_id")
domain_value_ids = domain_id.domain_line_ids.mapped("value_ids")
invalid_value_ids = domain_value_ids - tmpl_value_ids
invalid_attribute_ids = domain_attr_ids - tmpl_attribute_ids
if not invalid_attribute_ids and not invalid_value_ids:
continue
if not error_message:
error_message = _(
"Following Attribute/Value from restriction "
"are not present in template attributes/values. "
"Please make sure you are adding right restriction"
)
error_message += _("\nRestriction: %s", domain_id.name)
error_message += (
invalid_attribute_ids
and _(
"\nAttribute/s: %s", ", ".join(invalid_attribute_ids.mapped("name"))
)
or ""
)
error_message += (
invalid_value_ids
and _("\nValue/s: %s\n", ", ".join(invalid_value_ids.mapped("name")))
or ""
)
has_effect = False
for line_id in domain_id.domain_line_ids:
if line_id.attribute_id in tmpl_attribute_ids and set(
line_id.value_ids
).intersection(set(tmpl_value_ids)):
has_effect = True
break
if not has_effect:
error_message += _("\n\nRestriction: %s", domain_id.name)
if error_message:
raise ValidationError(error_message)
base_message = _(
"The following Configuration Restrictions have no effect on this "
"Template. i.e. They have no Attribute/Value combinations that are "
"present in the Template Attributes/Values.\n"
"Please only select Restrictions that relate to this Template."
)
raise ValidationError(base_message + error_message)


class ProductProduct(models.Model):
Expand Down
Loading