Item variants: validation added
This commit is contained in:
parent
2fb0654f97
commit
affb3ec220
@ -83,6 +83,7 @@ frappe.ui.form.on("Item", {
|
|||||||
|
|
||||||
validate: function(frm){
|
validate: function(frm){
|
||||||
erpnext.item.weight_to_validate(frm);
|
erpnext.item.weight_to_validate(frm);
|
||||||
|
erpnext.item.variants_can_not_be_created_manually(frm);
|
||||||
},
|
},
|
||||||
|
|
||||||
image: function(frm) {
|
image: function(frm) {
|
||||||
@ -209,4 +210,10 @@ $.extend(erpnext.item, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
variants_can_not_be_created_manually: function(frm) {
|
||||||
|
if (frm.doc.__islocal && frm.doc.variant_of)
|
||||||
|
frappe.throw(__("Variants can not be created manually, add item attributes in the template item"))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -50,6 +50,7 @@ class Item(WebsiteGenerator):
|
|||||||
|
|
||||||
if self.variant_of:
|
if self.variant_of:
|
||||||
self.copy_attributes_to_variant(frappe.get_doc("Item", self.variant_of), self)
|
self.copy_attributes_to_variant(frappe.get_doc("Item", self.variant_of), self)
|
||||||
|
|
||||||
self.check_warehouse_is_set_for_stock_item()
|
self.check_warehouse_is_set_for_stock_item()
|
||||||
self.check_stock_uom_with_bin()
|
self.check_stock_uom_with_bin()
|
||||||
self.add_default_uom_in_conversion_factor_table()
|
self.add_default_uom_in_conversion_factor_table()
|
||||||
@ -147,17 +148,21 @@ class Item(WebsiteGenerator):
|
|||||||
def validate_variants_are_unique(self):
|
def validate_variants_are_unique(self):
|
||||||
if not self.has_variants:
|
if not self.has_variants:
|
||||||
self.variants = []
|
self.variants = []
|
||||||
|
return
|
||||||
|
|
||||||
if self.variants and self.variant_of:
|
if self.variants:
|
||||||
|
if self.variant_of:
|
||||||
frappe.throw(_("Item cannot be a variant of a variant"))
|
frappe.throw(_("Item cannot be a variant of a variant"))
|
||||||
|
|
||||||
variants = []
|
variants = []
|
||||||
for d in self.variants:
|
for d in self.variants:
|
||||||
key = (d.item_attribute, d.item_attribute_value)
|
key = (d.item_attribute, d.item_attribute_value)
|
||||||
if key in variants:
|
if key in variants:
|
||||||
frappe.throw(_("{0} {1} is entered more than once in Item Variants table").format(d.item_attribute,
|
frappe.throw(_("{0} {1} is entered more than once in Item Variants table")
|
||||||
d.item_attribute_value), DuplicateVariant)
|
.format(d.item_attribute, d.item_attribute_value), DuplicateVariant)
|
||||||
variants.append(key)
|
variants.append(key)
|
||||||
|
else:
|
||||||
|
frappe.throw(_("Please enter atleast one attribute row in Item Variants table"))
|
||||||
|
|
||||||
def sync_variants(self):
|
def sync_variants(self):
|
||||||
variant_item_codes = self.get_variant_item_codes()
|
variant_item_codes = self.get_variant_item_codes()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user