Update new bom rate while replacing BOM (#11045)
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 91b5070..e3c61ed 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 @@
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