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 9a95e3b
Showing 1 changed file with 16 additions and 19 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

0 comments on commit 9a95e3b

Please sign in to comment.