Skip to content

Commit

Permalink
fix(po-analysis): handle SQL error due to empty data in IN() clause
Browse files Browse the repository at this point in the history
  • Loading branch information
navinrc committed Dec 10, 2024
1 parent 968762c commit 3c6f40b
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 3c6f40b

Please sign in to comment.