Skip to content

Commit

Permalink
[FIX] check product configurater steps and add warnings
Browse files Browse the repository at this point in the history
[FIX] tests fails issue

[IMP]
  • Loading branch information
Urvisha-OSI authored and Vandan-OSI committed Jun 24, 2024
1 parent fb5d191 commit a6baba3
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 19 deletions.
43 changes: 41 additions & 2 deletions product_configurator/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,47 @@ def write(self, vals):
configurable_templates = self.filtered(lambda template: template.config_ok)
if change_config_ok or configurable_templates:
self[:1].check_config_user_access()

return super().write(vals)
res = super().write(vals)
if "config_step_line_ids" in vals:
miss_attrs = list(
set(self.attribute_line_ids.ids)
- set(self.config_step_line_ids.attribute_line_ids.ids)
)
if miss_attrs:
attrs = [
x.attribute_id.name
for x in self.env["product.template.attribute.line"].browse(
miss_attrs
)
]
raise ValidationError(

Check warning on line 349 in product_configurator/models/product.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product.py#L349

Added line #L349 was not covered by tests
_(
"The following attributes are missing\
from Configuration Steps: %s",
(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:
raise ValidationError(
_(
"The following attributes have \
duplicates in Configuration Steps: %s",
(dupAttrs),
)
)
return res

@api.constrains("config_line_ids")
def _check_config_line_domain(self):
Expand Down
16 changes: 15 additions & 1 deletion product_configurator/models/product_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def validate_custom_val(self, val):
elif maxv and val > maxv:
raise ValidationError(
_(
"Selected custom value '%(name)s' must be lower than %(max_value)s"
"Selected custom value '%(name)s'\
must be lower than %(max_value)s"
)
% ({"name": self.name, "max_val": self.max_val + 1})
)
Expand Down Expand Up @@ -418,6 +419,19 @@ def name_search(self, name="", args=None, operator="ilike", limit=100):
):
args = [("id", "in", wiz_id.domain_attr_2_ids.ids)]

Check warning on line 420 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L420

Added line #L420 was not covered by tests

else:
field_prefix = wiz_id._prefixes.get("field_prefix")

Check warning on line 423 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L423

Added line #L423 was not covered by tests
if field_prefix and self.env.context.get('field_name') and wiz_id.domain_attr_ids and wiz_id.domain_attr_2_ids:
attrs_split = self.env.context.get('field_name').split(field_prefix)

Check warning on line 425 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L425

Added line #L425 was not covered by tests
if attrs_split and len(attrs_split) == 2 and not args[0][2]:
attribute_id = int(attrs_split[1])

Check warning on line 427 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L427

Added line #L427 was not covered by tests
domain_attr_ids = wiz_id.domain_attr_ids.filtered(lambda l:l.attribute_id.id == attribute_id)
domain_attr_2_ids = wiz_id.domain_attr_2_ids.filtered(lambda l:l.attribute_id.id == attribute_id)
if domain_attr_ids.ids:
args[0][2] = domain_attr_ids.ids

Check warning on line 431 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L431

Added line #L431 was not covered by tests
if domain_attr_2_ids.ids:
args[0][2] = domain_attr_2_ids.ids

Check warning on line 433 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L433

Added line #L433 was not covered by tests

product_tmpl_id = self.env.context.get("_cfg_product_tmpl_id")

Check warning on line 435 in product_configurator/models/product_attribute.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/models/product_attribute.py#L435

Added line #L435 was not covered by tests
if product_tmpl_id:
# TODO: Avoiding browse here could be a good performance enhancer
Expand Down
15 changes: 8 additions & 7 deletions product_configurator/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,14 @@ def test_06_configure_product(self):
"attribute_line_ids": [(6, 0, [self.attributeLine3.id])],
}
)
self.product_tmpl_id.write(
{
"config_step_line_ids": [
(6, 0, [self.configStepLine1.id, self.configStepLine2.id])
],
}
)
with self.assertRaises(ValidationError):
self.product_tmpl_id.write(
{
"config_step_line_ids": [
(6, 0, [self.configStepLine1.id, self.configStepLine2.id])
],
}
)

# configure product
self.product_tmpl_id.configure_product()
Expand Down
1 change: 1 addition & 0 deletions product_configurator/views/product_config_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
/>
<field name="config_step_name" />
<field name="product_id" />
<field name="product_preset_id" invisible="not product_preset_id" readonly="1" />
</group>
<notebook>
<page name="custom_vals" string="Custom Values">
Expand Down
22 changes: 13 additions & 9 deletions product_configurator/wizard/product_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def get_state_selection(self):
return steps

open_lines = wiz.config_session_id.get_open_step_lines()

if open_lines:
open_steps = open_lines.mapped(lambda x: (str(x.id), x.config_step_id.name))
steps = open_steps if wiz.product_id else steps + open_steps
Expand Down Expand Up @@ -359,7 +358,6 @@ def apply_onchange_values(self, values, field_name, field_onchange):
elif values and value[0][2]:
self.dyn_field_2_value = key
self.domain_attr_2_ids = [(6, 0, value[0][2])]

Check warning on line 360 in product_configurator/wizard/product_configurator.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/wizard/product_configurator.py#L359-L360

Added lines #L359 - L360 were not covered by tests

vals = self.get_form_vals(
dynamic_fields=dynamic_fields,
domains=domains,
Expand All @@ -375,9 +373,10 @@ def onchange(self, values, field_name, field_onchange):
onchange_values = self.apply_onchange_values(

Check warning on line 373 in product_configurator/wizard/product_configurator.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/wizard/product_configurator.py#L373

Added line #L373 was not covered by tests
values=values, field_name=field_name, field_onchange=field_onchange
)

field_prefix = self._prefixes.get("field_prefix")

Check warning on line 376 in product_configurator/wizard/product_configurator.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/wizard/product_configurator.py#L376

Added line #L376 was not covered by tests

if field_name == ['product_preset_id']:
self.with_context(preset_values=values)._onchange_product_preset()
vals = onchange_values.get("value", {})

Check warning on line 380 in product_configurator/wizard/product_configurator.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/wizard/product_configurator.py#L379-L380

Added lines #L379 - L380 were not covered by tests
for key, val in vals.items():
if isinstance(val, int) and key.startswith(field_prefix):
Expand Down Expand Up @@ -451,7 +450,11 @@ def _onchange_state(self):
@api.onchange("product_preset_id")
def _onchange_product_preset(self):
"""Set value ids as from product preset"""
pta_value_ids = self.product_preset_id.product_template_attribute_value_ids
preset_id = self.product_preset_id

Check warning on line 453 in product_configurator/wizard/product_configurator.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/wizard/product_configurator.py#L453

Added line #L453 was not covered by tests
if not preset_id and self.env.context.get('preset_values'):
preset_id = self.env.context.get('preset_values').get('product_preset_id')
preset_id = self.env["product.product"].browse(preset_id)
pta_value_ids = preset_id.product_template_attribute_value_ids
attr_value_ids = pta_value_ids.mapped("product_attribute_value_id")
self.value_ids = attr_value_ids

Check warning on line 459 in product_configurator/wizard/product_configurator.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/wizard/product_configurator.py#L455-L459

Added lines #L455 - L459 were not covered by tests

Expand Down Expand Up @@ -871,7 +874,6 @@ def read(self, fields=None, load="_classic_read"):

field_prefix = self._prefixes.get("field_prefix")
custom_field_prefix = self._prefixes.get("custom_field_prefix")

Check warning on line 876 in product_configurator/wizard/product_configurator.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/wizard/product_configurator.py#L875-L876

Added lines #L875 - L876 were not covered by tests

attr_vals = [f for f in fields if f.startswith(field_prefix)]
custom_attr_vals = [f for f in fields if f.startswith(custom_field_prefix)]

Expand Down Expand Up @@ -1020,10 +1022,12 @@ def action_reset(self):
self.config_session_id.unlink()

Check warning on line 1022 in product_configurator/wizard/product_configurator.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/wizard/product_configurator.py#L1021-L1022

Added lines #L1021 - L1022 were not covered by tests
except Exception:
session = self.env["product.config.step"]

Check warning on line 1024 in product_configurator/wizard/product_configurator.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/wizard/product_configurator.py#L1024

Added line #L1024 was not covered by tests
action = session_product_tmpl_id.with_context({}).create_config_wizard(
click_next=False
)
return action
if session_product_tmpl_id:
action = session_product_tmpl_id.with_context({}).create_config_wizard(

Check warning on line 1026 in product_configurator/wizard/product_configurator.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/wizard/product_configurator.py#L1026

Added line #L1026 was not covered by tests
click_next=False
)
return action
return False

Check warning on line 1030 in product_configurator/wizard/product_configurator.py

View check run for this annotation

Codecov / codecov/patch

product_configurator/wizard/product_configurator.py#L1029-L1030

Added lines #L1029 - L1030 were not covered by tests

def get_wizard_action(self, view_cache=False, wizard=None):
"""Return action of wizard
Expand Down

0 comments on commit a6baba3

Please sign in to comment.