From e132c457f25baa4dc8d738be856a0f5db1db4e4a Mon Sep 17 00:00:00 2001 From: ravibharathi656 Date: Fri, 19 Sep 2025 00:05:00 +0530 Subject: [PATCH] fix(profit and loss statement): incorrect total calculation (cherry picked from commit b7c6d8e2a6913ac9c6b38da731c01039eb3f2c85) --- .../accounts/report/financial_statements.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 89f36364826..f48adac6c51 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -323,18 +323,24 @@ def prepare_data(accounts, balance_must_be, period_list, company_currency, accum def filter_out_zero_value_rows(data, parent_children_map, show_zero_values=False): + def get_all_parents(account, parent_children_map): + for parent, children in parent_children_map.items(): + for child in children: + if child["name"] == account and parent: + accounts_to_show.add(parent) + get_all_parents(parent, parent_children_map) + data_with_value = [] + accounts_to_show = set() + for d in data: if show_zero_values or d.get("has_value"): + accounts_to_show.add(d.get("account")) + get_all_parents(d.get("account"), parent_children_map) + + for d in data: + if d.get("account") in accounts_to_show: data_with_value.append(d) - else: - # show group with zero balance, if there are balances against child - children = [child.name for child in parent_children_map.get(d.get("account")) or []] - if children: - for row in data: - if row.get("account") in children and row.get("has_value"): - data_with_value.append(d) - break return data_with_value