From 8fd3828ef5705a081623d18b140683963ae465f0 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Thu, 5 Feb 2015 17:16:45 +0530 Subject: [PATCH 1/2] Update Item Desc Button Removed from BOM, Item desc automatically updated in BOM on save of item master --- erpnext/manufacturing/doctype/bom/bom.js | 12 ------------ erpnext/manufacturing/doctype/bom/bom.py | 10 ---------- erpnext/stock/doctype/item/item.py | 8 +++++++- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index a5d500f87c..a230cf4ab9 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -9,9 +9,6 @@ cur_frm.cscript.refresh = function(doc,dt,dn){ if (!doc.__islocal && doc.docstatus<2) { cur_frm.add_custom_button(__("Update Cost"), cur_frm.cscript.update_cost, "icon-money", "btn-default"); - - cur_frm.add_custom_button(__("Update Item Description"), cur_frm.cscript.update_item_desc, - "icon-tag", "btn-default"); } } @@ -25,15 +22,6 @@ cur_frm.cscript.update_cost = function() { }) } -cur_frm.cscript.update_item_desc = function() { - return frappe.call({ - doc: cur_frm.doc, - method: "update_item_desc", - callback: function(r) { - if(!r.exc) cur_frm.refresh_fields(); - } - }) -} cur_frm.add_fetch("item", "description", "description"); cur_frm.add_fetch("item", "item_name", "item_name"); cur_frm.add_fetch("item", "stock_uom", "uom"); diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index f77628a417..7cc3919e2f 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -134,16 +134,6 @@ class BOM(Document): self.ignore_validate_update_after_submit = True self.calculate_cost() self.save() - - def update_item_desc(self): - if self.docstatus < 2: - self.ignore_validate_update_after_submit = True - self.description = frappe.db.get_value("Item", self.item, "description") - for d in self.get("items"): - d.description = frappe.db.get_value("Item", d.item_code, "description") - for d in self.get("exploded_items"): - d.description = frappe.db.get_value("Item", d.item_code, "description") - self.save() def get_bom_unitcost(self, bom_no): bom = frappe.db.sql("""select name, total_cost/quantity as unit_cost from `tabBOM` diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index d77cd1d50b..633ead189e 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -69,6 +69,7 @@ class Item(WebsiteGenerator): self.validate_name_with_item_group() self.update_item_price() self.sync_variants() + self.update_item_desc() def get_context(self, context): context["parent_groups"] = get_parent_item_groups(self.item_group) + \ @@ -433,7 +434,12 @@ class Item(WebsiteGenerator): row = self.append("website_specifications") row.label = label row.description = desc - + + def update_item_desc(self): + frappe.db.sql("""update `tabBOM` set description = %s where item = %s and docstatus < 2""",(self.description, self.name)) + frappe.db.sql("""update `tabBOM Item` set description = %s where item_code = %s and docstatus < 2""",(self.description, self.name)) + frappe.db.sql("""update `tabBOM Explosion Item` set description = %s where item_code = %s and docstatus < 2""",(self.description, self.name)) + def validate_end_of_life(item_code, end_of_life=None, verbose=1): if not end_of_life: end_of_life = frappe.db.get_value("Item", item_code, "end_of_life") From 845be908d68dacf0aa194afd75d87592b943c693 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Fri, 6 Feb 2015 16:15:45 +0530 Subject: [PATCH 2/2] function moved to validate --- erpnext/stock/doctype/item/item.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 633ead189e..351f7178c9 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -57,6 +57,7 @@ class Item(WebsiteGenerator): self.validate_reorder_level() self.validate_warehouse_for_reorder() self.validate_variants() + self.update_item_desc() if not self.get("__islocal"): self.old_item_group = frappe.db.get_value(self.doctype, self.name, "item_group") @@ -69,7 +70,6 @@ class Item(WebsiteGenerator): self.validate_name_with_item_group() self.update_item_price() self.sync_variants() - self.update_item_desc() def get_context(self, context): context["parent_groups"] = get_parent_item_groups(self.item_group) + \ @@ -436,9 +436,10 @@ class Item(WebsiteGenerator): row.description = desc def update_item_desc(self): - frappe.db.sql("""update `tabBOM` set description = %s where item = %s and docstatus < 2""",(self.description, self.name)) - frappe.db.sql("""update `tabBOM Item` set description = %s where item_code = %s and docstatus < 2""",(self.description, self.name)) - frappe.db.sql("""update `tabBOM Explosion Item` set description = %s where item_code = %s and docstatus < 2""",(self.description, self.name)) + if frappe.db.get_value('BOM',self.name, 'description') != self.description: + frappe.db.sql("""update `tabBOM` set description = %s where item = %s and docstatus < 2""",(self.description, self.name)) + frappe.db.sql("""update `tabBOM Item` set description = %s where item_code = %s and docstatus < 2""",(self.description, self.name)) + frappe.db.sql("""update `tabBOM Explosion Item` set description = %s where item_code = %s and docstatus < 2""",(self.description, self.name)) def validate_end_of_life(item_code, end_of_life=None, verbose=1): if not end_of_life: