From 88cb132fd130cb34d1a269dc348d1fc491b8131c Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 17 Jun 2026 19:01:39 +0530 Subject: [PATCH] refactor(postgres): port Purchase Invoice expense-account queries to the query builder Co-Authored-By: Claude Opus 4.8 (1M context) --- .../purchase_invoice/services/expense_account.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/services/expense_account.py b/erpnext/accounts/doctype/purchase_invoice/services/expense_account.py index df03a9a838f..3a84382b585 100644 --- a/erpnext/accounts/doctype/purchase_invoice/services/expense_account.py +++ b/erpnext/accounts/doctype/purchase_invoice/services/expense_account.py @@ -55,10 +55,13 @@ class ExpenseAccountService: else: # check if 'Stock Received But Not Billed' account is credited in Purchase receipt or not if item.purchase_receipt: - negative_expense_booked_in_pr = frappe.db.sql( - """select name from `tabGL Entry` - where voucher_type='Purchase Receipt' and voucher_no=%s and account = %s""", - (item.purchase_receipt, stock_not_billed_account), + negative_expense_booked_in_pr = frappe.db.exists( + "GL Entry", + { + "voucher_type": "Purchase Receipt", + "voucher_no": item.purchase_receipt, + "account": stock_not_billed_account, + }, ) if negative_expense_booked_in_pr: