Skip to content

Commit

Permalink
[FIX][T1902][OCA#59]product_configurator : clear value from next step…
Browse files Browse the repository at this point in the history
… if not available
  • Loading branch information
bizzappdev authored and RUS committed Apr 8, 2022
1 parent 8272744 commit c7b787f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
5 changes: 5 additions & 0 deletions product_configurator/models/product_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ def write(self, vals):
"""Validate configuration when writing new values to session"""
# TODO: Issue warning when writing to value_ids or custom_val_ids
res = super(ProductConfigSession, self).write(vals)
value_ids = self.value_ids.ids
avail_val_ids = self.values_available(value_ids, value_ids)
if set(value_ids) - set(avail_val_ids):
self.value_ids = [(6, 0, avail_val_ids)]
valid = self.validate_configuration(final=False)
if not valid:
raise ValidationError(_('Invalid Configuration'))
Expand Down Expand Up @@ -977,6 +981,7 @@ def validate_configuration(
# Check if all all the values passed are not restricted
avail_val_ids = self.values_available(value_ids, value_ids)
if set(value_ids) - set(avail_val_ids):
print(set(value_ids), set(avail_val_ids))
return False

# Check if custom values are allowed
Expand Down
37 changes: 30 additions & 7 deletions product_configurator/tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def test_02_product_configuration_restriction(self):
})
attr_line2 = self.ProductAttributeLine.create({
'attribute_id': self.attr_size.id,
'value_ids': [(6, 0, [self.value_S.id, self.value_M.id, self.value_L.id])],
'value_ids': [
(6, 0, [self.value_S.id, self.value_M.id, self.value_L.id])],
'required': True,
'product_tmpl_id': product.id,
})
Expand Down Expand Up @@ -142,17 +143,39 @@ def test_02_product_configuration_restriction(self):
'product_tmpl_id': product.id,
})
product_config_wizard.action_next_step()
setattr(product_config_wizard, '__attribute-' + str(self.attr_color.id), str(self.value_blue.id))
setattr(
product_config_wizard,
'__attribute-' + str(self.attr_color.id),
str(self.value_blue.id)
)
product_config_wizard.action_next_step()
setattr(product_config_wizard, '__attribute-' + str(self.attr_size.id), str(self.value_M.id))
setattr(
product_config_wizard,
'__attribute-' + str(self.attr_size.id),
str(self.value_M.id)
)
product_config_wizard.action_previous_step()
setattr(product_config_wizard, '__attribute-' + str(self.attr_color.id), str(self.value_green.id))
setattr(
product_config_wizard,
'__attribute-' + str(self.attr_color.id),
str(self.value_green.id)
)
product_config_wizard.action_next_step()
setattr(product_config_wizard, '__attribute-' + str(self.attr_size.id), str(self.value_S.id))
setattr(product_config_wizard, '__attribute-' + str(self.attr_width.id), str(self.value_A.id))
setattr(
product_config_wizard,
'__attribute-' + str(self.attr_size.id),
str(self.value_S.id)
)
setattr(
product_config_wizard,
'__attribute-' + str(self.attr_width.id),
str(self.value_A.id)
)
product_config_wizard.action_next_step()
new_variant = product.product_variant_ids.filtered(
lambda variant: variant.attribute_value_ids == (self.value_green + self.value_S + self.value_A)
lambda variant:
variant.attribute_value_ids
== (self.value_green + self.value_S + self.value_A)
)
self.assertNotEqual(
new_variant.id,
Expand Down
26 changes: 1 addition & 25 deletions product_configurator/wizard/product_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,29 +777,6 @@ def unlink(self):
self.mapped('config_session_id').unlink()
return super(ProductConfigurator, self).unlink()

def clear_values_in_future_steps(self, active_cfg_line_id):
"""Set values of fields in step 'active_cfg_line_id' to null/false"""
field_prefix = self._prefixes.get('field_prefix')
custom_field_prefix = self._prefixes.get('custom_field_prefix')

fields = self.fields_get()
active_cfg_line_fields_dict = {}

for attr_line in active_cfg_line_id.attribute_line_ids:
attr_id = attr_line.attribute_id.id
field_name = field_prefix + str(attr_id)
custom_field_name = custom_field_prefix + str(attr_id)

if field_name in fields:
if fields[field_name]['type'] == 'many2one':
active_cfg_line_fields_dict.update({field_name: False})
elif fields[field_name]['type'] == 'many2many':
active_cfg_line_fields_dict.update({field_name: []})
if custom_field_name in fields:
active_cfg_line_fields_dict.update({custom_field_name: False})

self.write(active_cfg_line_fields_dict)

@api.multi
def action_next_step(self):
"""Proceeds to the next step of the configuration process. This usually
Expand All @@ -809,6 +786,7 @@ def action_next_step(self):
More importantly it sets metadata on the context
variable so the fields_get and fields_view_get methods can generate the
appropriate dynamic content"""

wizard_action = {
'type': 'ir.actions.act_window',
'res_model': self._name,
Expand Down Expand Up @@ -838,7 +816,6 @@ def action_next_step(self):
else:
self.state = 'configure'
return wizard_action

adjacent_steps = self.config_session_id.get_adjacent_steps()
next_step = adjacent_steps.get('next_step')

Expand All @@ -847,7 +824,6 @@ def action_next_step(self):
next_step = self.config_session_id.config_step
else:
next_step = str(next_step.id) if next_step else None

if next_step:
self.state = next_step
self.config_session_id.config_step = next_step
Expand Down

0 comments on commit c7b787f

Please sign in to comment.