Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
10.0 - Raise more meaningful Warnings,
Browse files Browse the repository at this point in the history
Modified for new refactored domain validations.
  • Loading branch information
Richard deMeester committed May 5, 2017
1 parent 00785c1 commit 0bb2c03
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions product_configurator/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,15 @@ 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
: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
"""
Expand All @@ -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
Expand All @@ -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 = {}

Expand All @@ -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

Expand Down

0 comments on commit 0bb2c03

Please sign in to comment.