From cb4ec72370c25e442d3f8ba0d4ec3522316aeab1 Mon Sep 17 00:00:00 2001 From: Henil Maru Date: Sun, 30 Aug 2026 15:56:28 +0530 Subject: [PATCH] fix: Work Order picks wrong Delivery Date when Sales Order has the same item in multiple rows (#58526) --- 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 18779c39632..23fccbedbbb 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -527,7 +527,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) @@ -543,9 +543,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)