Merge pull request #55976 from frappe/mergify/bp/version-16-hotfix/pr-55943

refactor: ignore cancelled GLE's while looking for account (backport #55943)
This commit is contained in:
Sudharsanan Ashok
2026-06-16 17:26:50 +05:30
committed by GitHub

View File

@@ -541,11 +541,19 @@ def get_party_gle_currency(party_type, party, company):
def get_party_gle_account(party_type, party, company): def get_party_gle_account(party_type, party, company):
def generator(): def generator():
existing_gle_account = frappe.db.sql( gl = qb.DocType("GL Entry")
"""select account from `tabGL Entry` existing_gle_account = (
where docstatus=1 and company=%(company)s and party_type=%(party_type)s and party=%(party)s qb.from_(gl)
limit 1""", .select(gl.account)
{"company": company, "party_type": party_type, "party": party}, .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 return existing_gle_account[0][0] if existing_gle_account else None