Skip to content

Commit 0349e7a

Browse files
committed
fix: always exclude pcv entries except for closing account head
1 parent 3faeb16 commit 0349e7a

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

erpnext/accounts/doctype/financial_report_template/financial_report_engine.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,18 @@ def _handle_balance_accumulation(self, balances_data):
680680
account_data.unaccumulate_values()
681681

682682
def _apply_standard_filters(self, query, table, doctype: str = "GL Entry"):
683-
if self.filters.get("ignore_closing_entries"):
684-
if doctype == "GL Entry":
685-
query = query.where(table.voucher_type != "Period Closing Voucher")
686-
else:
687-
query = query.where(table.is_period_closing_voucher_entry == 0)
683+
# Exclude PCV-generated entries except those posted to a closing-account-head
684+
# so BS retained earnings survive while P&L reversal entries are filtered out
685+
pcv = frappe.qb.DocType("Period Closing Voucher")
686+
closing_heads = frappe.qb.from_(pcv).select(pcv.closing_account_head).where(pcv.docstatus == 1)
687+
688+
if doctype == "GL Entry":
689+
is_pcv = table.voucher_type == "Period Closing Voucher"
690+
else:
691+
# Account Closing Balance
692+
is_pcv = table.is_period_closing_voucher_entry == 1
693+
694+
query = query.where(~is_pcv | table.account.isin(closing_heads))
688695

689696
if self.filters.get("project"):
690697
projects = self.filters.get("project")

0 commit comments

Comments
 (0)