From 2f279a6eb417af7d43608fc699fe64ae1c9aaae3 Mon Sep 17 00:00:00 2001 From: Navin R C <40256832+navinrc@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:49:38 +0530 Subject: [PATCH] fix: SQL syntax error in Purchase Receipt query for empty filters (#44636) fix(po-analysis): handle SQL error due to empty data in IN() clause Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 48b49cdea43684b56307e7a353e5bf77e8c32013) --- .../purchase_order_analysis/purchase_order_analysis.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/erpnext/buying/report/purchase_order_analysis/purchase_order_analysis.py b/erpnext/buying/report/purchase_order_analysis/purchase_order_analysis.py index 6d2034d1878..75658e28780 100644 --- a/erpnext/buying/report/purchase_order_analysis/purchase_order_analysis.py +++ b/erpnext/buying/report/purchase_order_analysis/purchase_order_analysis.py @@ -103,6 +103,11 @@ def get_received_amount_data(data): pr = frappe.qb.DocType("Purchase Receipt") pr_item = frappe.qb.DocType("Purchase Receipt Item") + po_items = [row.name for row in data] + + if not po_items: + return frappe._dict() + query = ( frappe.qb.from_(pr) .inner_join(pr_item) @@ -111,12 +116,10 @@ def get_received_amount_data(data): pr_item.purchase_order_item, Sum(pr_item.base_amount).as_("received_qty_amount"), ) - .where((pr_item.parent == pr.name) & (pr.docstatus == 1)) + .where((pr.docstatus == 1) & (pr_item.purchase_order_item.isin(po_items))) .groupby(pr_item.purchase_order_item) ) - query = query.where(pr_item.purchase_order_item.isin([row.name for row in data])) - data = query.run() if not data: