From 7e5a9f5c0ef178e2b622b49002bdb666e314a9b6 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 4 Oct 2017 15:51:34 +0530 Subject: [PATCH] Update new bom rate while replacing BOM (#11045) --- .../doctype/bom_update_tool/bom_update_tool.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py b/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py index 91b5070dbd..e3c61ed516 100644 --- a/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py +++ b/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py @@ -30,12 +30,13 @@ class BOMUpdateTool(Document): frappe.throw(_("The selected BOMs are not for the same item")) def update_new_bom(self): - current_bom_unitcost = frappe.db.sql("""select total_cost/quantity - from `tabBOM` where name = %s""", self.current_bom) - current_bom_unitcost = current_bom_unitcost and flt(current_bom_unitcost[0][0]) or 0 + new_bom_unitcost = frappe.db.sql("""select total_cost/quantity + from `tabBOM` where name = %s""", self.new_bom) + new_bom_unitcost = flt(new_bom_unitcost[0][0]) if new_bom_unitcost else 0 + frappe.db.sql("""update `tabBOM Item` set bom_no=%s, rate=%s, amount=stock_qty*%s where bom_no = %s and docstatus < 2""", - (self.new_bom, current_bom_unitcost, current_bom_unitcost, self.current_bom)) + (self.new_bom, new_bom_unitcost, new_bom_unitcost, self.current_bom)) def get_parent_boms(self): return [d[0] for d in frappe.db.sql("""select distinct parent