From 856ba2419462a94e21a89668e9f113865c07c1a8 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 8 Apr 2026 12:15:28 +0000 Subject: [PATCH] fix(manufacturing): check remaining qty to calculate operating cost (backport #53983) (#54128) Co-authored-by: Sudharsanan Ashok <135326972+Sudharsanan11@users.noreply.github.com> fix(manufacturing): check remaining qty to calculate operating cost (#53983) --- erpnext/stock/doctype/stock_entry/stock_entry.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index ae5c390fdae..d62ce4e2cb4 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -3928,9 +3928,12 @@ def get_operating_cost_per_unit(work_order=None, bom_no=None): for d in work_order.get("operations"): if 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) + if not (remaining_qty := flt(d.completed_qty - work_order.produced_qty)): + continue + operating_cost_per_unit += ( + flt(d.actual_operating_cost - get_consumed_operating_cost(work_order.name, bom_no)) + / remaining_qty + ) elif work_order.qty: operating_cost_per_unit += flt(d.planned_operating_cost) / flt(work_order.qty)