From affb3ec220aa3639a723be84d9da816868f2cc58 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 11 May 2015 12:25:11 +0530 Subject: [PATCH] Item variants: validation added --- erpnext/stock/doctype/item/item.js | 9 ++++++++- erpnext/stock/doctype/item/item.py | 25 +++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index 55d6d33ce7..b31b682984 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -83,8 +83,9 @@ frappe.ui.form.on("Item", { validate: function(frm){ erpnext.item.weight_to_validate(frm); + erpnext.item.variants_can_not_be_created_manually(frm); }, - + image: function(frm) { refresh_field("image_view"); }, @@ -208,5 +209,11 @@ $.extend(erpnext.item, { validated = 0; } }, + + 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")) + } + }); diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index dcf390c406..de605021bd 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -50,6 +50,7 @@ class Item(WebsiteGenerator): if self.variant_of: self.copy_attributes_to_variant(frappe.get_doc("Item", self.variant_of), self) + self.check_warehouse_is_set_for_stock_item() self.check_stock_uom_with_bin() self.add_default_uom_in_conversion_factor_table() @@ -147,17 +148,21 @@ class Item(WebsiteGenerator): def validate_variants_are_unique(self): if not self.has_variants: self.variants = [] + return - if self.variants and self.variant_of: - frappe.throw(_("Item cannot be a variant of a variant")) - - variants = [] - for d in self.variants: - key = (d.item_attribute, d.item_attribute_value) - if key in variants: - frappe.throw(_("{0} {1} is entered more than once in Item Variants table").format(d.item_attribute, - d.item_attribute_value), DuplicateVariant) - variants.append(key) + if self.variants: + if self.variant_of: + frappe.throw(_("Item cannot be a variant of a variant")) + + variants = [] + for d in self.variants: + key = (d.item_attribute, d.item_attribute_value) + if key in variants: + frappe.throw(_("{0} {1} is entered more than once in Item Variants table") + .format(d.item_attribute, d.item_attribute_value), DuplicateVariant) + variants.append(key) + else: + frappe.throw(_("Please enter atleast one attribute row in Item Variants table")) def sync_variants(self): variant_item_codes = self.get_variant_item_codes()