From 43ec80eb201cb07cac809a57d63fba8b362b3f52 Mon Sep 17 00:00:00 2001 From: Shruti Singh Date: Tue, 25 Sep 2018 19:14:43 +0530 Subject: [PATCH] [FIX][T1902][#59]product_configurator : clear value from next step if not available --- product_configurator/models/product_config.py | 5 +++ product_configurator/tests/test_create.py | 37 +++++++++++++++---- .../wizard/product_configurator.py | 26 +------------ 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/product_configurator/models/product_config.py b/product_configurator/models/product_config.py index 1b1cd5cc7e..fc9b25baa9 100644 --- a/product_configurator/models/product_config.py +++ b/product_configurator/models/product_config.py @@ -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')) @@ -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 diff --git a/product_configurator/tests/test_create.py b/product_configurator/tests/test_create.py index 1040e7c569..c1f7df5d86 100644 --- a/product_configurator/tests/test_create.py +++ b/product_configurator/tests/test_create.py @@ -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, }) @@ -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, diff --git a/product_configurator/wizard/product_configurator.py b/product_configurator/wizard/product_configurator.py index f962f06a13..14d905b1d0 100644 --- a/product_configurator/wizard/product_configurator.py +++ b/product_configurator/wizard/product_configurator.py @@ -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 @@ -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, @@ -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') @@ -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