mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-19 21:19:19 +00:00
[fix] Additional Costs patch fixed for version 4 to 5 migration
This commit is contained in:
@@ -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")
|
|
||||||
@@ -16,15 +16,24 @@ def execute():
|
|||||||
and (se.purpose not in ('Manufacture', 'Repack') or ifnull(additional_operating_cost, 0)=0)
|
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`
|
stock_entries = frappe.db.sql_list("""select name from `tabStock Entry`
|
||||||
where purpose in ('Manufacture', 'Repack') and ifnull(additional_operating_cost, 0)!=0
|
where purpose in ('Manufacture', 'Repack') and ifnull({0}, 0)!=0
|
||||||
and docstatus < 2""")
|
and docstatus < 2""".format(operating_cost_fieldname))
|
||||||
|
|
||||||
for d in stock_entries:
|
for d in stock_entries:
|
||||||
stock_entry = frappe.get_doc("Stock Entry", d)
|
stock_entry = frappe.get_doc("Stock Entry", d)
|
||||||
stock_entry.append("additional_costs", {
|
stock_entry.append("additional_costs", {
|
||||||
"description": "Additional Operating Cost",
|
"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])
|
number_of_fg_items = len([t.t_warehouse for t in stock_entry.get("items") if t.t_warehouse])
|
||||||
@@ -33,7 +42,7 @@ def execute():
|
|||||||
d.valuation_rate = d.incoming_rate
|
d.valuation_rate = d.incoming_rate
|
||||||
|
|
||||||
if d.bom_no or (d.t_warehouse and number_of_fg_items == 1):
|
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_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"))
|
d.basic_amount = flt(flt(d.basic_rate) *flt(d.transfer_qty), d.precision("basic_amount"))
|
||||||
|
|||||||
Reference in New Issue
Block a user