fixes in validation for item varients

This commit is contained in:
Neil Trini Lasrado 2015-05-21 14:38:39 +05:30
parent 71b7a52990
commit 753e40b4d5

View File

@ -154,7 +154,7 @@ class Item(WebsiteGenerator):
if self.variant_of:
frappe.throw(_("Item cannot be a variant of a variant"))
variants = []
variants, attributes = [], {}
for d in self.variants:
key = (d.item_attribute, d.item_attribute_value)
if key in variants:
@ -162,8 +162,10 @@ class Item(WebsiteGenerator):
.format(d.item_attribute, d.item_attribute_value), DuplicateVariant)
variants.append(key)
if not d.item_attribute_value in [t.attribute_value for t in frappe.db.get_all("Item Attribute Value",
fields=["attribute_value"], filters={"parent": d.item_attribute })]:
attributes.setdefault(d.item_attribute, [t.attribute_value for t in frappe.db.get_all("Item Attribute Value",
fields=["attribute_value"], filters={"parent": d.item_attribute })])
if d.item_attribute_value not in attributes.get(d.item_attribute):
frappe.throw(_("Attribute value {0} does not exist in Item Attribute Master.").format(d.item_attribute_value))
else:
frappe.throw(_("Please enter atleast one attribute row in Item Variants table"))