Skip to content

Commit

Permalink
[IMP]Configurator Tab duplicate Checks and Warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Vandan-OSI committed Jul 2, 2024
1 parent 1db72ba commit 9da9898
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
35 changes: 16 additions & 19 deletions product_configurator/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from collections import Counter

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -348,29 +349,25 @@ def write(self, vals):
]
raise ValidationError(
_(
"The following attributes are missing\
from Configuration Steps: %s",
(attrs),
"The following attributes are missing from Configuration Steps: %s",
(",".join(attrs)),
)
)
all_attrs = self.config_step_line_ids.attribute_line_ids.ids
check = False
dupAttrs = []
for config_step in self.config_step_line_ids[1:]:
check = any(e in all_attrs for e in config_step.attribute_line_ids.ids)
if check:
dupAttrs.append(
[
attr.attribute_id.name
for attr in config_step.attribute_line_ids
]
)
if check and dupAttrs:
couter = []
for config_step in self.config_step_line_ids:
couter.extend(config_step.attribute_line_ids.ids)
counter = Counter(couter)
duplicates = []
for k,v in dict(counter).items():
if v > 1:
duplicates.append(k)
if duplicates:
duplicates = self.env['product.template.attribute.line'].browse(duplicates)
duplicates = ",".join(duplicates.mapped('attribute_id.name'))
raise ValidationError(
_(
"The following attributes have \
duplicates in Configuration Steps: %s",
(dupAttrs),
"The following attributes have duplicates in Configuration Steps: %s",
(duplicates),
)
)
return res
Expand Down
9 changes: 5 additions & 4 deletions product_configurator/wizard/product_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ def apply_onchange_values(self, values, field_name, field_onchange):
state = self.state

cfg_vals = self.env["product.attribute.value"]
if values.get("value_ids", []):
cfg_vals = self.env["product.attribute.value"].browse(
values.get("value_ids", [])[0][2]
)
# TODO: VP Need to Check
# if values.get("value_ids", []):
# cfg_vals = self.env["product.attribute.value"].browse(
# values.get("value_ids", [])[0][2]
# )
if not cfg_vals:
cfg_vals = self.value_ids

Expand Down

0 comments on commit 9da9898

Please sign in to comment.