diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index 340a3157594..b40dc3792c0 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -2004,20 +2004,20 @@ def stop_unstop(work_order, status): @frappe.whitelist() -def query_sales_order(production_item): - out = frappe.db.sql_list( - """ - select distinct so.name from `tabSales Order` so, `tabSales Order Item` so_item - where so_item.parent=so.name and so_item.item_code=%s and so.docstatus=1 - union - select distinct so.name from `tabSales Order` so, `tabPacked Item` pi_item - where pi_item.parent=so.name and pi_item.item_code=%s and so.docstatus=1 - """, - (production_item, production_item), +def query_sales_order(production_item: str) -> list[str]: + return frappe.get_list( + "Sales Order", + filters=[ + ["Sales Order", "docstatus", "=", 1], + ], + or_filters=[ + ["Sales Order Item", "item_code", "=", production_item], + ["Packed Item", "item_code", "=", production_item], + ], + pluck="name", + distinct=True, ) - return out - @frappe.whitelist() def make_job_card(work_order, operations):