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: