mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-16 18:24:10 +00:00
refactor(postgres): port Trial Balance report query to the query builder
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.query_builder.functions import Sum
|
from frappe.query_builder.functions import Max, Sum
|
||||||
from frappe.utils import add_days, cstr, flt, formatdate, getdate
|
from frappe.utils import add_days, cstr, flt, formatdate, getdate
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
@@ -82,12 +82,21 @@ def validate_filters(filters):
|
|||||||
|
|
||||||
|
|
||||||
def get_data(filters):
|
def get_data(filters):
|
||||||
accounts = frappe.db.sql(
|
accounts = frappe.get_all(
|
||||||
"""select name, account_number, parent_account, account_name, root_type, report_type, is_group, lft, rgt
|
"Account",
|
||||||
|
filters={"company": filters.company},
|
||||||
from `tabAccount` where company=%s order by lft""",
|
fields=[
|
||||||
filters.company,
|
"name",
|
||||||
as_dict=True,
|
"account_number",
|
||||||
|
"parent_account",
|
||||||
|
"account_name",
|
||||||
|
"root_type",
|
||||||
|
"report_type",
|
||||||
|
"is_group",
|
||||||
|
"lft",
|
||||||
|
"rgt",
|
||||||
|
],
|
||||||
|
order_by="lft",
|
||||||
)
|
)
|
||||||
company_currency = filters.presentation_currency or erpnext.get_company_currency(filters.company)
|
company_currency = filters.presentation_currency or erpnext.get_company_currency(filters.company)
|
||||||
|
|
||||||
@@ -240,7 +249,8 @@ def get_opening_balance(
|
|||||||
frappe.qb.from_(closing_balance)
|
frappe.qb.from_(closing_balance)
|
||||||
.select(
|
.select(
|
||||||
closing_balance.account,
|
closing_balance.account,
|
||||||
closing_balance.account_currency,
|
# account_currency is constant per grouped account -> Max() keeps the GROUP BY postgres-valid
|
||||||
|
Max(closing_balance.account_currency).as_("account_currency"),
|
||||||
Sum(closing_balance.debit).as_("debit"),
|
Sum(closing_balance.debit).as_("debit"),
|
||||||
Sum(closing_balance.credit).as_("credit"),
|
Sum(closing_balance.credit).as_("credit"),
|
||||||
Sum(closing_balance.debit_in_account_currency).as_("debit_in_account_currency"),
|
Sum(closing_balance.debit_in_account_currency).as_("debit_in_account_currency"),
|
||||||
|
|||||||
Reference in New Issue
Block a user