From 0bb2c03f841d8a846a33244666c5a758fe50c89e Mon Sep 17 00:00:00 2001 From: Richard deMeester Date: Wed, 26 Apr 2017 08:49:12 +1000 Subject: [PATCH] 10.0 - Raise more meaningful Warnings, Modified for new refactored domain validations. --- product_configurator/models/product.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/product_configurator/models/product.py b/product_configurator/models/product.py index e124294e..56cdd063 100644 --- a/product_configurator/models/product.py +++ b/product_configurator/models/product.py @@ -414,7 +414,7 @@ def validate_domains_against_sels(self, domains, sel_val_ids): return avail @api.multi - def values_available(self, attr_val_ids, sel_val_ids): + def values_available(self, attr_val_ids, sel_val_ids, do_raise=False): """Determines whether the attr_values from the product_template are available for selection given the configuration ids and the dependencies set on the product template @@ -422,6 +422,7 @@ def values_available(self, attr_val_ids, sel_val_ids): :param attr_val_ids: list of attribute value ids to check for availability :param sel_val_ids: list of attribute value ids already selected + :param do_raise: boolean on whether to raise a warning or just fail :returns: list of available attribute values """ @@ -437,7 +438,18 @@ def values_available(self, attr_val_ids, sel_val_ids): avail = self.validate_domains_against_sels(domains, sel_val_ids) if avail: avail_val_ids.append(attr_val_id) - + elif do_raise: + if len(config_lines) == 1 and config_lines[0].rule_description: + raise ValidationError(config_lines[0].rule_description) + else: + attribute_value = \ + self.env['product.attribute.value'].browse(attr_val_id) + raise ValidationError( + _('%s for %s is not valid in this configuration') % + (attribute_value.name, + attribute_value.attribute_id.name + ) + ) return avail_val_ids @api.multi @@ -450,12 +462,12 @@ def validate_configuration(self, value_ids, :param custom_vals: custom values dict {attr_id: custom_val} :param final: boolean marker to check required attributes. pass false to check non-final configurations + :param do_raise: boolean on whether to raise a warning or just fail :returns: Error dict with reason of validation failure or True """ - # TODO: Raise ConfigurationError with reason - # Check if required values are missing for final configuration + # TODO: Check if required values are missing for final configuration if custom_vals is None: custom_vals = {} @@ -475,7 +487,8 @@ def validate_configuration(self, value_ids, return False # Check if all all the values passed are not restricted - avail_val_ids = self.values_available(value_ids, value_ids) + avail_val_ids = self.values_available(value_ids, value_ids, + do_raise=do_raise) if set(value_ids) - set(avail_val_ids): return False