From d6956790d8f8940696783bc7ca85438ecd7d4b6e Mon Sep 17 00:00:00 2001 From: Henil Maru Date: Wed, 26 Aug 2026 20:41:14 +0530 Subject: [PATCH] fix: Work Order picks wrong Delivery Date when Sales Order has the same item in multiple rows (#58448) --- erpnext/manufacturing/doctype/work_order/work_order.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index a0357751635..428c274d5cd 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -516,7 +516,7 @@ class WorkOrder(Document): PackedItem = frappe.qb.DocType("Packed Item") ProductBundleItem = frappe.qb.DocType("Product Bundle Item") - so = ( + so_query = ( frappe.qb.from_(SalesOrder) .inner_join(SalesOrderItem) .on(SalesOrderItem.parent == SalesOrder.name) @@ -533,9 +533,13 @@ class WorkOrder(Document): | (ProductBundleItem.item_code == production_item) ) ) - .run(as_dict=1) ) + if self.sales_order_item: + so_query = so_query.where(SalesOrderItem.name == self.sales_order_item) + + so = so_query.run(as_dict=1) + if not so: so = ( frappe.qb.from_(SalesOrder)