mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 12:19:12 +00:00
fix: modify for new changes
This commit is contained in:
@@ -1503,7 +1503,7 @@ def add_non_stock_items_cost(stock_entry, work_order, expense_account, job_card=
|
|||||||
|
|
||||||
|
|
||||||
def add_operating_cost_component_wise(
|
def add_operating_cost_component_wise(
|
||||||
stock_entry, work_order=None, operating_cost_per_unit=None, op_expense_account=None, job_card=None
|
stock_entry, work_order=None, consumed_operating_cost=None, op_expense_account=None, job_card=None
|
||||||
):
|
):
|
||||||
if not work_order:
|
if not work_order:
|
||||||
return False
|
return False
|
||||||
@@ -1527,11 +1527,11 @@ def add_operating_cost_component_wise(
|
|||||||
get_component_account(wc.operating_component, stock_entry.company) or op_expense_account
|
get_component_account(wc.operating_component, stock_entry.company) or op_expense_account
|
||||||
)
|
)
|
||||||
actual_cp_operating_cost = flt(
|
actual_cp_operating_cost = flt(
|
||||||
flt(wc.operating_cost) * flt(flt(row.actual_operation_time) / 60.0),
|
flt(wc.operating_cost) * flt(flt(row.actual_operation_time) / 60.0) - consumed_operating_cost,
|
||||||
row.precision("actual_operating_cost"),
|
row.precision("actual_operating_cost"),
|
||||||
)
|
)
|
||||||
|
|
||||||
per_unit_cost = flt(actual_cp_operating_cost) / flt(row.completed_qty)
|
per_unit_cost = flt(actual_cp_operating_cost) / flt(row.completed_qty - work_order.produced_qty)
|
||||||
|
|
||||||
if per_unit_cost and expense_account:
|
if per_unit_cost and expense_account:
|
||||||
stock_entry.append(
|
stock_entry.append(
|
||||||
@@ -1542,6 +1542,7 @@ def add_operating_cost_component_wise(
|
|||||||
wc.operating_component, row.operation
|
wc.operating_component, row.operation
|
||||||
),
|
),
|
||||||
"amount": per_unit_cost * flt(stock_entry.fg_completed_qty),
|
"amount": per_unit_cost * flt(stock_entry.fg_completed_qty),
|
||||||
|
"has_operating_cost": 1,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1558,13 +1559,20 @@ def get_component_account(parent, company):
|
|||||||
|
|
||||||
|
|
||||||
def add_operations_cost(stock_entry, work_order=None, expense_account=None, job_card=None):
|
def add_operations_cost(stock_entry, work_order=None, expense_account=None, job_card=None):
|
||||||
from erpnext.stock.doctype.stock_entry.stock_entry import get_operating_cost_per_unit
|
from erpnext.stock.doctype.stock_entry.stock_entry import (
|
||||||
|
get_consumed_operating_cost,
|
||||||
|
get_operating_cost_per_unit,
|
||||||
|
)
|
||||||
|
|
||||||
operating_cost_per_unit = get_operating_cost_per_unit(work_order, stock_entry.bom_no)
|
operating_cost_per_unit = get_operating_cost_per_unit(work_order, stock_entry.bom_no)
|
||||||
|
|
||||||
if operating_cost_per_unit:
|
if operating_cost_per_unit:
|
||||||
cost_added = add_operating_cost_component_wise(
|
cost_added = add_operating_cost_component_wise(
|
||||||
stock_entry, work_order, operating_cost_per_unit, expense_account, job_card=job_card
|
stock_entry,
|
||||||
|
work_order,
|
||||||
|
get_consumed_operating_cost(work_order.name, stock_entry.bom_no),
|
||||||
|
expense_account,
|
||||||
|
job_card=job_card,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not cost_added:
|
if not cost_added:
|
||||||
|
|||||||
@@ -3417,26 +3417,27 @@ def get_work_order_details(work_order, company):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_operating_cost_per_unit(work_order=None, bom_no=None):
|
def get_consumed_operating_cost(wo_name, bom_no):
|
||||||
def get_consumed_operating_cost(wo_name, bom_no):
|
table = frappe.qb.DocType("Stock Entry")
|
||||||
table = frappe.qb.DocType("Stock Entry")
|
child_table = frappe.qb.DocType("Landed Cost Taxes and Charges")
|
||||||
child_table = frappe.qb.DocType("Landed Cost Taxes and Charges")
|
query = (
|
||||||
query = (
|
frappe.qb.from_(child_table)
|
||||||
frappe.qb.from_(child_table)
|
.join(table)
|
||||||
.join(table)
|
.on(child_table.parent == table.name)
|
||||||
.on(child_table.parent == table.name)
|
.select(Sum(child_table.amount).as_("consumed_cost"))
|
||||||
.select(Sum(child_table.amount).as_("consumed_cost"))
|
.where(
|
||||||
.where(
|
(table.docstatus == 1)
|
||||||
(table.docstatus == 1)
|
& (table.work_order == wo_name)
|
||||||
& (table.work_order == wo_name)
|
& (table.purpose == "Manufacture")
|
||||||
& (table.purpose == "Manufacture")
|
& (table.bom_no == bom_no)
|
||||||
& (table.bom_no == bom_no)
|
& (child_table.has_operating_cost == 1)
|
||||||
& (child_table.has_operating_cost == 1)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
cost = query.run(pluck="consumed_cost")
|
)
|
||||||
return cost[0] if cost and cost[0] else 0
|
cost = query.run(pluck="consumed_cost")
|
||||||
|
return cost[0] if cost and cost[0] else 0
|
||||||
|
|
||||||
|
|
||||||
|
def get_operating_cost_per_unit(work_order=None, bom_no=None):
|
||||||
operating_cost_per_unit = 0
|
operating_cost_per_unit = 0
|
||||||
if work_order:
|
if work_order:
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user