From 6475df89c939033159f8971e938eb96dafc3afea Mon Sep 17 00:00:00 2001 From: ervishnucs Date: Mon, 15 Jun 2026 18:22:30 +0530 Subject: [PATCH] refactor: ignore cancelled GLE's while looking for account (cherry picked from commit 40942401df8bda9baaa47e390fee2158465c6e8e) --- erpnext/accounts/party.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 7f0583f0d1d..7bf6828cf91 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -541,11 +541,19 @@ def get_party_gle_currency(party_type, party, company): def get_party_gle_account(party_type, party, company): def generator(): - existing_gle_account = frappe.db.sql( - """select account from `tabGL Entry` - where docstatus=1 and company=%(company)s and party_type=%(party_type)s and party=%(party)s - limit 1""", - {"company": company, "party_type": party_type, "party": party}, + gl = qb.DocType("GL Entry") + existing_gle_account = ( + qb.from_(gl) + .select(gl.account) + .where( + (gl.docstatus == 1) + & (gl.company == company) + & (gl.party_type == party_type) + & (gl.party == party) + & (gl.is_cancelled == 0) + ) + .limit(1) + .run() ) return existing_gle_account[0][0] if existing_gle_account else None