Skip to content

Commit 3c8a066

Browse files
committed
fix: filter opening entries in first year in custom financial statement
1 parent ba01d66 commit 3c8a066

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

erpnext/accounts/doctype/financial_report_template/financial_report_engine.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ def __init__(self, filters: dict[str, Any], periods: list[dict]):
464464
self.periods = periods
465465
self.company = filters.get("company")
466466
self.account_meta = {} # {name: {account_name, account_number}}
467+
self.ignore_opening_entries = False
467468

468469
def fetch_account_balances(self, accounts: list[dict]) -> dict[str, AccountData]:
469470
"""
@@ -501,6 +502,8 @@ def _get_opening_balances(self, accounts: list[str]) -> dict[str, dict[str, dict
501502
"""
502503
Return opening balances for *all accounts* defaulting to zero.
503504
"""
505+
self.ignore_opening_entries = False
506+
504507
if frappe.get_single_value("Accounts Settings", "ignore_account_closing_balance"):
505508
return self._get_opening_balances_from_gl(accounts)
506509

@@ -522,6 +525,8 @@ def _get_opening_balances(self, accounts: list[str]) -> dict[str, dict[str, dict
522525
closing_data = self._get_closing_balances(accounts, closing_voucher.name)
523526

524527
if sum(closing_data.values()) != 0.0:
528+
# opening in current period
529+
self.ignore_opening_entries = True
525530
return self._rebase_closing_balances(closing_data, closing_voucher.period_end_date)
526531

527532
return self._get_opening_balances_from_gl(accounts)
@@ -616,7 +621,10 @@ def _get_gl_movements(self, account_names: list[str]) -> list[dict]:
616621
.groupby(gl_table.account)
617622
)
618623

619-
if not frappe.get_single_value("Accounts Settings", "ignore_is_opening_check_for_reporting"):
624+
ignore_is_opening = frappe.get_single_value(
625+
"Accounts Settings", "ignore_is_opening_check_for_reporting"
626+
)
627+
if self.ignore_opening_entries and not ignore_is_opening:
620628
query = query.where(gl_table.is_opening == "No")
621629

622630
# Add period-specific columns

0 commit comments

Comments
 (0)