fix(manufacturing): validate delivered qty in production plan

(cherry picked from commit eda8a621c6)
This commit is contained in:
Sudharsanan11
2025-12-22 15:26:33 +05:30
committed by Mergify
parent d3f434b803
commit c01f20da00

View File

@@ -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)