From c01f20da00bec7a29826e1eaa396acc64d87fcab Mon Sep 17 00:00:00 2001 From: Sudharsanan11 Date: Mon, 22 Dec 2025 15:26:33 +0530 Subject: [PATCH] fix(manufacturing): validate delivered qty in production plan (cherry picked from commit eda8a621c65bc0a250407605782acf7457ca79e9) --- .../production_plan/production_plan.py | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index c4b0aa26fce..74ccdfd02aa 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -369,6 +369,15 @@ class ProductionPlan(Document): pi = frappe.qb.DocType("Packed Item") + pending_qty = ( + frappe.qb.terms.Case() + .when( + (so_item.work_order_qty > so_item.delivered_qty), + (((so_item.qty - so_item.work_order_qty) * pi.qty) / so_item.qty), + ) + .else_(((so_item.qty - so_item.delivered_qty) * pi.qty) / so_item.qty) + ) + packed_items_query = ( frappe.qb.from_(so_item) .from_(pi) @@ -376,7 +385,7 @@ class ProductionPlan(Document): pi.parent, pi.item_code, pi.warehouse.as_("warehouse"), - (((so_item.qty - so_item.work_order_qty) * pi.qty) / so_item.qty).as_("pending_qty"), + pending_qty.as_("pending_qty"), pi.parent_item, pi.description, so_item.name, @@ -387,7 +396,16 @@ class ProductionPlan(Document): & (so_item.docstatus == 1) & (pi.parent_item == so_item.item_code) & (so_item.parent.isin(so_list)) - & (so_item.qty > so_item.work_order_qty) + & ( + ( + (so_item.work_order_qty > so_item.delivered_qty) + & (so_item.qty > so_item.work_order_qty) + ) + | ( + (so_item.work_order_qty <= so_item.delivered_qty) + & (so_item.qty > so_item.delivered_qty) + ) + ) & ( ExistsCriterion( frappe.qb.from_(bom)