From 13df8a40ef209113f0e18b233f202d68f3bc3395 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Thu, 23 Jul 2015 12:46:59 +0530 Subject: [PATCH] Validation added to prevent user to Manage Variants if Item Template is Unsaved. Prevented message stating variants updated while saving item template if there are no variants against that item Template --- erpnext/stock/doctype/item/item.js | 8 ++++++-- erpnext/stock/doctype/item/item.py | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index 58b1adb8db7..3bd5657d597 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -86,8 +86,12 @@ frappe.ui.form.on("Item", { }, manage_variants: function(frm) { - frappe.route_options = {"item_code": frm.doc.name }; - frappe.set_route("List", "Manage Variants"); + if (cur_frm.doc.__unsaved==1) { + frappe.throw(__("You have unsaved changes. Please save.")) + } else { + frappe.route_options = {"item_code": frm.doc.name }; + frappe.set_route("List", "Manage Variants"); + } } }); diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index a2e0ade50c9..d3d8e9c6a18 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -325,7 +325,8 @@ class Item(WebsiteGenerator): for d in variants: update_variant(self.name, d) updated.append(d.item_code) - frappe.msgprint(_("Item Variants {0} updated").format(", ".join(updated))) + if updated: + frappe.msgprint(_("Item Variants {0} updated").format(", ".join(updated))) def validate_has_variants(self): if not self.has_variants and frappe.db.get_value("Item", self.name, "has_variants"):