Merge pull request #3571 from neilLasrado/item-varients
Fixes for Item Attributes
This commit is contained in:
commit
0e6f92efa8
@ -8,8 +8,14 @@ from frappe import _
|
|||||||
|
|
||||||
class ItemAttribute(Document):
|
class ItemAttribute(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
self.validate_duplication()
|
||||||
|
self.validate_attribute_values()
|
||||||
|
|
||||||
|
|
||||||
|
def validate_duplication(self):
|
||||||
values, abbrs = [], []
|
values, abbrs = [], []
|
||||||
for d in self.item_attribute_values:
|
for d in self.item_attribute_values:
|
||||||
|
d.abbr = d.abbr.upper()
|
||||||
if d.attribute_value in values:
|
if d.attribute_value in values:
|
||||||
frappe.throw(_("{0} must appear only once").format(d.attribute_value))
|
frappe.throw(_("{0} must appear only once").format(d.attribute_value))
|
||||||
values.append(d.attribute_value)
|
values.append(d.attribute_value)
|
||||||
@ -17,3 +23,14 @@ class ItemAttribute(Document):
|
|||||||
if d.abbr in abbrs:
|
if d.abbr in abbrs:
|
||||||
frappe.throw(_("{0} must appear only once").format(d.abbr))
|
frappe.throw(_("{0} must appear only once").format(d.abbr))
|
||||||
abbrs.append(d.abbr)
|
abbrs.append(d.abbr)
|
||||||
|
|
||||||
|
def validate_attribute_values(self):
|
||||||
|
attribute_values = []
|
||||||
|
for d in self.item_attribute_values:
|
||||||
|
attribute_values.append(d.attribute_value)
|
||||||
|
|
||||||
|
variant_attributes = frappe.db.sql("select DISTINCT attribute_value from `tabVariant Attribute` where attribute=%s", self.name)
|
||||||
|
if variant_attributes:
|
||||||
|
for d in variant_attributes:
|
||||||
|
if d[0] not in attribute_values:
|
||||||
|
frappe.throw(_("Attribute Value {0} cannot be removed from {1} as Item Variants exist with this Attribute.").format(d[0], self.name))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user