Skip to content

Commit

Permalink
fix: improved query for gelling all child accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
ljain112 committed Jul 2, 2024
1 parent cbd25ae commit 960c85e
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions erpnext/accounts/report/general_ledger/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import frappe
from frappe import _, _dict
from frappe.query_builder import Criterion
from frappe.utils import cstr, getdate

from erpnext import get_company_currency, get_default_company
Expand Down Expand Up @@ -319,18 +320,22 @@ def get_accounts_with_children(accounts):
if not isinstance(accounts, list):
accounts = [d.strip() for d in accounts.strip().split(",") if d]

all_accounts = []
for d in accounts:
account = frappe.get_cached_doc("Account", d)
if account:
children = frappe.get_all(
"Account", filters={"lft": [">=", account.lft], "rgt": ["<=", account.rgt]}
)
all_accounts += [c.name for c in children]
else:
frappe.throw(_("Account: {0} does not exist").format(d))
if not accounts:
return

doctype = frappe.qb.DocType("Account")
accounts_detail = (
frappe.qb.from_(doctype)
.select(doctype.name, doctype.lft, doctype.rgt)
.where(doctype.name.isin(accounts))
.run(as_dict=True)
)

conditions = []
for account in accounts_detail:
conditions.append((doctype.lft >= account.lft) & (doctype.rgt <= account.rgt))

return list(set(all_accounts)) if all_accounts else None
return (frappe.qb.from_(doctype).select(doctype.name).where(Criterion.any(conditions))).run(pluck=True)


def get_data_with_opening_closing(filters, account_details, accounting_dimensions, gl_entries):
Expand Down

0 comments on commit 960c85e

Please sign in to comment.