[fix] Additional Costs patch fixed for version 4 to 5 migration
diff --git a/erpnext/patches/v5_0/capacity_planning.py b/erpnext/patches/v5_0/capacity_planning.py
deleted file mode 100644
index f12f1f7..0000000
--- a/erpnext/patches/v5_0/capacity_planning.py
+++ /dev/null
@@ -1,9 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-
-import frappe
-
-def execute():
- frappe.reload_doc("stock", "doctype", "stock_entry")
- if "total_fixed_cost" in frappe.db.get_table_columns("Stock Entry"):
- frappe.db.sql("update `tabStock Entry` set additional_operating_cost = total_fixed_cost")
diff --git a/erpnext/patches/v5_4/stock_entry_additional_costs.py b/erpnext/patches/v5_4/stock_entry_additional_costs.py
index 96d6b3d..325d6cf 100644
--- a/erpnext/patches/v5_4/stock_entry_additional_costs.py
+++ b/erpnext/patches/v5_4/stock_entry_additional_costs.py
@@ -16,15 +16,24 @@
and (se.purpose not in ('Manufacture', 'Repack') or ifnull(additional_operating_cost, 0)=0)
""")
+ stock_entry_db_columns = frappe.db.get_table_columns("Stock Entry")
+ if "additional_operating_cost" in stock_entry_db_columns:
+ operating_cost_fieldname = "additional_operating_cost"
+ elif "total_fixed_cost" in stock_entry_db_columns:
+ operating_cost_fieldname = "total_fixed_cost"
+ else:
+ return
+
+
stock_entries = frappe.db.sql_list("""select name from `tabStock Entry`
- where purpose in ('Manufacture', 'Repack') and ifnull(additional_operating_cost, 0)!=0
- and docstatus < 2""")
+ where purpose in ('Manufacture', 'Repack') and ifnull({0}, 0)!=0
+ and docstatus < 2""".format(operating_cost_fieldname))
for d in stock_entries:
stock_entry = frappe.get_doc("Stock Entry", d)
stock_entry.append("additional_costs", {
"description": "Additional Operating Cost",
- "amount": stock_entry.additional_operating_cost
+ "amount": stock_entry.get(operating_cost_fieldname)
})
number_of_fg_items = len([t.t_warehouse for t in stock_entry.get("items") if t.t_warehouse])
@@ -33,7 +42,7 @@
d.valuation_rate = d.incoming_rate
if d.bom_no or (d.t_warehouse and number_of_fg_items == 1):
- d.additional_cost = stock_entry.additional_operating_cost
+ d.additional_cost = stock_entry.get(operating_cost_fieldname)
d.basic_rate = flt(d.valuation_rate) - flt(d.additional_cost)
d.basic_amount = flt(flt(d.basic_rate) *flt(d.transfer_qty), d.precision("basic_amount"))