Validate numeric attribute value based on range defined in template (#11981)

This commit is contained in:
Nabin Hait 2017-12-13 18:40:52 +05:30 committed by GitHub
parent 96d6498226
commit aaf378e340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,7 +56,7 @@ def validate_item_variant_attributes(item, args=None):
if not args: if not args:
args = {d.attribute.lower():d.attribute_value for d in item.attributes} args = {d.attribute.lower():d.attribute_value for d in item.attributes}
attribute_values, numeric_values = get_attribute_values() attribute_values, numeric_values = get_attribute_values(item)
for attribute, value in args.items(): for attribute, value in args.items():
if not value: if not value:
@ -96,16 +96,17 @@ def validate_item_attribute_value(attributes_list, attribute, attribute_value, i
frappe.throw(_("Value {0} for Attribute {1} does not exist in the list of valid Item Attribute Values for Item {2}").format( frappe.throw(_("Value {0} for Attribute {1} does not exist in the list of valid Item Attribute Values for Item {2}").format(
attribute_value, attribute, item), InvalidItemAttributeValueError, title=_('Invalid Attribute')) attribute_value, attribute, item), InvalidItemAttributeValueError, title=_('Invalid Attribute'))
def get_attribute_values(): def get_attribute_values(item):
if not frappe.flags.attribute_values: if not frappe.flags.attribute_values:
attribute_values = {} attribute_values = {}
numeric_values = {} numeric_values = {}
for t in frappe.get_all("Item Attribute Value", fields=["parent", "attribute_value"]): for t in frappe.get_all("Item Attribute Value", fields=["parent", "attribute_value"]):
attribute_values.setdefault(t.parent.lower(), []).append(t.attribute_value) attribute_values.setdefault(t.parent.lower(), []).append(t.attribute_value)
for t in frappe.get_all('Item Attribute', for t in frappe.get_all('Item Variant Attribute',
fields=["name", "from_range", "to_range", "increment"], filters={'numeric_values': 1}): fields=["attribute", "from_range", "to_range", "increment"],
numeric_values[t.name.lower()] = t filters={'numeric_values': 1, 'parent': item.variant_of}):
numeric_values[t.attribute.lower()] = t
frappe.flags.attribute_values = attribute_values frappe.flags.attribute_values = attribute_values
frappe.flags.numeric_values = numeric_values frappe.flags.numeric_values = numeric_values