From 44ca5878b87043f0c65059351aade378aea47042 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 17 Jun 2026 17:35:56 +0530 Subject: [PATCH] refactor(postgres): port Consolidated Financial Statement report query to the query builder Co-Authored-By: Claude Opus 4.8 (1M context) --- .../consolidated_financial_statement.py | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py index 78baf4484d5..fba7054e0a7 100644 --- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py +++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py @@ -347,11 +347,10 @@ def get_data(companies, root_type, balance_must_be, fiscal_year, filters=None, i filters.end_date = end_date gl_entries_by_account = {} - for root in frappe.db.sql( - """select lft, rgt from tabAccount - where root_type=%s and ifnull(parent_account, '') = ''""", - root_type, - as_dict=1, + for root in frappe.get_all( + "Account", + filters={"root_type": root_type, "parent_account": ["is", "not set"]}, + fields=["lft", "rgt"], ): set_gl_entries_by_account( start_date, @@ -512,9 +511,11 @@ def get_companies(filters): def get_subsidiary_companies(company): lft, rgt = frappe.get_cached_value("Company", company, ["lft", "rgt"]) - return frappe.db.sql_list( - f"""select name from `tabCompany` - where lft >= {lft} and rgt <= {rgt} order by lft, rgt""" + return frappe.get_all( + "Company", + filters={"lft": [">=", lft], "rgt": ["<=", rgt]}, + pluck="name", + order_by="lft, rgt", ) @@ -604,14 +605,10 @@ def set_gl_entries_by_account( company_lft, company_rgt = frappe.get_cached_value("Company", filters.get("company"), ["lft", "rgt"]) - companies = frappe.db.sql( - """ select name, default_currency from `tabCompany` - where lft >= %(company_lft)s and rgt <= %(company_rgt)s""", - { - "company_lft": company_lft, - "company_rgt": company_rgt, - }, - as_dict=1, + companies = frappe.get_all( + "Company", + filters={"lft": [">=", company_lft], "rgt": ["<=", company_rgt]}, + fields=["name", "default_currency"], ) currency_info = frappe._dict(