Merge pull request #2482 from neilLasrado/fix-cost
Fixed cost calculation Error
diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js
index cb96478..1b1dc62 100644
--- a/erpnext/manufacturing/doctype/bom/bom.js
+++ b/erpnext/manufacturing/doctype/bom/bom.js
@@ -83,6 +83,7 @@
cur_frm.cscript.time_in_mins = cur_frm.cscript.hour_rate;
+cur_frm.cscript.fixed_cycle_cost = cur_frm.cscript.hour_rate;
cur_frm.cscript.item_code = function(doc, cdt, cdn) {
get_bom_material_detail(doc, cdt, cdn);
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index e8a8682..199ade9 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -285,7 +285,10 @@
if not d.hour_rate:
d.hour_rate = flt(w[0])
- fixed_cost += flt(w[1])
+ if d.fixed_cycle_cost == None:
+ d.fixed_cycle_cost= flt(w[1])
+
+ fixed_cost += d.fixed_cycle_cost
if d.hour_rate and d.time_in_mins:
d.operating_cost = flt(d.hour_rate) * flt(d.time_in_mins) / 60.0
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 4c97581..33fa396 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -89,3 +89,4 @@
erpnext.patches.v4_2.fix_gl_entries_for_stock_transactions
erpnext.patches.v4_2.update_requested_and_ordered_qty
execute:frappe.delete_doc("DocType", "Contact Control")
+erpnext.patches.v4_2.recalculate_bom_costs
diff --git a/erpnext/patches/v4_2/recalculate_bom_costs.py b/erpnext/patches/v4_2/recalculate_bom_costs.py
new file mode 100644
index 0000000..25fd7f3
--- /dev/null
+++ b/erpnext/patches/v4_2/recalculate_bom_costs.py
@@ -0,0 +1,19 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+ for d in frappe.db.sql("""select bom.name from `tabBOM` bom where bom.docstatus < 2 and
+ exists(select bom_item.name from `tabBOM Operation` bom_op where
+ bom.name = bom_op.parent and bom_op.fixed_cycle_cost IS NOT NULL)""", as_dict=1):
+ try:
+ bom = frappe.get_doc('BOM', d.name)
+ bom.ignore_validate_update_after_submit = True
+ bom.calculate_cost()
+ bom.save()
+ frappe.db.commit()
+ except:
+ frappe.db.rollback()
+
\ No newline at end of file