mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 19:19:17 +00:00
fix: stock entry manufacture - fix operating cost calculation
This commit is contained in:
@@ -1574,6 +1574,7 @@ def add_operations_cost(stock_entry, work_order=None, expense_account=None, job_
|
|||||||
"expense_account": expense_account,
|
"expense_account": expense_account,
|
||||||
"description": _("Operating Cost as per Work Order / BOM"),
|
"description": _("Operating Cost as per Work Order / BOM"),
|
||||||
"amount": operating_cost_per_unit * flt(stock_entry.fg_completed_qty),
|
"amount": operating_cost_per_unit * flt(stock_entry.fg_completed_qty),
|
||||||
|
"has_operating_cost": 1,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
"col_break3",
|
"col_break3",
|
||||||
"amount",
|
"amount",
|
||||||
"base_amount",
|
"base_amount",
|
||||||
"has_corrective_cost"
|
"has_corrective_cost",
|
||||||
|
"has_operating_cost"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -70,13 +71,20 @@
|
|||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Has Corrective Cost",
|
"label": "Has Corrective Cost",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "has_operating_cost",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Has Operating Cost",
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"grid_page_length": 50,
|
"grid_page_length": 50,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2025-06-09 10:22:20.286641",
|
"modified": "2025-07-16 15:27:59.175530",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Landed Cost Taxes and Charges",
|
"name": "Landed Cost Taxes and Charges",
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class LandedCostTaxesandCharges(Document):
|
|||||||
exchange_rate: DF.Float
|
exchange_rate: DF.Float
|
||||||
expense_account: DF.Link | None
|
expense_account: DF.Link | None
|
||||||
has_corrective_cost: DF.Check
|
has_corrective_cost: DF.Check
|
||||||
|
has_operating_cost: DF.Check
|
||||||
parent: DF.Data
|
parent: DF.Data
|
||||||
parentfield: DF.Data
|
parentfield: DF.Data
|
||||||
parenttype: DF.Data
|
parenttype: DF.Data
|
||||||
|
|||||||
@@ -3418,6 +3418,25 @@ def get_work_order_details(work_order, company):
|
|||||||
|
|
||||||
|
|
||||||
def get_operating_cost_per_unit(work_order=None, bom_no=None):
|
def get_operating_cost_per_unit(work_order=None, bom_no=None):
|
||||||
|
def get_consumed_operating_cost(wo_name, bom_no):
|
||||||
|
table = frappe.qb.DocType("Stock Entry")
|
||||||
|
child_table = frappe.qb.DocType("Landed Cost Taxes and Charges")
|
||||||
|
query = (
|
||||||
|
frappe.qb.from_(child_table)
|
||||||
|
.join(table)
|
||||||
|
.on(child_table.parent == table.name)
|
||||||
|
.select(Sum(child_table.amount).as_("consumed_cost"))
|
||||||
|
.where(
|
||||||
|
(table.docstatus == 1)
|
||||||
|
& (table.work_order == wo_name)
|
||||||
|
& (table.purpose == "Manufacture")
|
||||||
|
& (table.bom_no == bom_no)
|
||||||
|
& (child_table.has_operating_cost == 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
cost = query.run(pluck="consumed_cost")
|
||||||
|
return cost[0] if cost and cost[0] else 0
|
||||||
|
|
||||||
operating_cost_per_unit = 0
|
operating_cost_per_unit = 0
|
||||||
if work_order:
|
if work_order:
|
||||||
if (
|
if (
|
||||||
@@ -3434,7 +3453,9 @@ def get_operating_cost_per_unit(work_order=None, bom_no=None):
|
|||||||
|
|
||||||
for d in work_order.get("operations"):
|
for d in work_order.get("operations"):
|
||||||
if flt(d.completed_qty):
|
if flt(d.completed_qty):
|
||||||
operating_cost_per_unit += flt(d.actual_operating_cost) / flt(d.completed_qty)
|
operating_cost_per_unit += flt(
|
||||||
|
d.actual_operating_cost - get_consumed_operating_cost(work_order.name, bom_no)
|
||||||
|
) / flt(d.completed_qty - work_order.produced_qty)
|
||||||
elif work_order.qty:
|
elif work_order.qty:
|
||||||
operating_cost_per_unit += flt(d.planned_operating_cost) / flt(work_order.qty)
|
operating_cost_per_unit += flt(d.planned_operating_cost) / flt(work_order.qty)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user