Skip to content

Commit 2f279a6

Browse files
navinrcmergify[bot]
authored andcommitted
fix: SQL syntax error in Purchase Receipt query for empty filters (frappe#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 48b49cd)
1 parent 6bb2b76 commit 2f279a6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

erpnext/buying/report/purchase_order_analysis/purchase_order_analysis.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ def get_received_amount_data(data):
103103
pr = frappe.qb.DocType("Purchase Receipt")
104104
pr_item = frappe.qb.DocType("Purchase Receipt Item")
105105

106+
po_items = [row.name for row in data]
107+
108+
if not po_items:
109+
return frappe._dict()
110+
106111
query = (
107112
frappe.qb.from_(pr)
108113
.inner_join(pr_item)
@@ -111,12 +116,10 @@ def get_received_amount_data(data):
111116
pr_item.purchase_order_item,
112117
Sum(pr_item.base_amount).as_("received_qty_amount"),
113118
)
114-
.where((pr_item.parent == pr.name) & (pr.docstatus == 1))
119+
.where((pr.docstatus == 1) & (pr_item.purchase_order_item.isin(po_items)))
115120
.groupby(pr_item.purchase_order_item)
116121
)
117122

118-
query = query.where(pr_item.purchase_order_item.isin([row.name for row in data]))
119-
120123
data = query.run()
121124

122125
if not data:

0 commit comments

Comments
 (0)