Validate numeric attribute value based on range defined in template (#11981)
diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py
index f40d519..27a2a3a 100644
--- a/erpnext/controllers/item_variant.py
+++ b/erpnext/controllers/item_variant.py
@@ -56,7 +56,7 @@
if not args:
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():
if not value:
@@ -96,16 +96,17 @@
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'))
-def get_attribute_values():
+def get_attribute_values(item):
if not frappe.flags.attribute_values:
attribute_values = {}
numeric_values = {}
for t in frappe.get_all("Item Attribute Value", fields=["parent", "attribute_value"]):
attribute_values.setdefault(t.parent.lower(), []).append(t.attribute_value)
- for t in frappe.get_all('Item Attribute',
- fields=["name", "from_range", "to_range", "increment"], filters={'numeric_values': 1}):
- numeric_values[t.name.lower()] = t
+ for t in frappe.get_all('Item Variant Attribute',
+ fields=["attribute", "from_range", "to_range", "increment"],
+ filters={'numeric_values': 1, 'parent': item.variant_of}):
+ numeric_values[t.attribute.lower()] = t
frappe.flags.attribute_values = attribute_values
frappe.flags.numeric_values = numeric_values