From d54f8318fba2b60eaad4a93a811a5b569c3344dc Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Wed, 27 Dec 2023 16:32:57 +0530 Subject: [PATCH] fix: incorrect total when Accumulating values --- .../accounts/report/financial_statements.py | 20 ++++++++++++++---- .../profit_and_loss_statement.py | 21 ++++++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 7355c4b8a1..004a9299ea 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -211,7 +211,13 @@ def get_data( ignore_accumulated_values_for_fy, ) accumulate_values_into_parents(accounts, accounts_by_name, period_list) - out = prepare_data(accounts, balance_must_be, period_list, company_currency) + out = prepare_data( + accounts, + balance_must_be, + period_list, + company_currency, + accumulated_values=filters.accumulated_values, + ) out = filter_out_zero_value_rows(out, parent_children_map) if out and total: @@ -270,7 +276,7 @@ def accumulate_values_into_parents(accounts, accounts_by_name, period_list): ) + d.get("opening_balance", 0.0) -def prepare_data(accounts, balance_must_be, period_list, company_currency): +def prepare_data(accounts, balance_must_be, period_list, company_currency, accumulated_values): data = [] year_start_date = period_list[0]["year_start_date"].strftime("%Y-%m-%d") year_end_date = period_list[-1]["year_end_date"].strftime("%Y-%m-%d") @@ -310,8 +316,14 @@ def prepare_data(accounts, balance_must_be, period_list, company_currency): has_value = True total += flt(row[period.key]) - row["has_value"] = has_value - row["total"] = total + if accumulated_values: + # when 'accumulated_values' is enabled, periods have running balance. + # so, last period will have the net amount. + row["has_value"] = has_value + row["total"] = flt(d.get(period_list[-1].key, 0.0), 3) + else: + row["has_value"] = has_value + row["total"] = total data.append(row) return data diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py index 66353358a0..0b7ce51891 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py +++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py @@ -82,14 +82,25 @@ def get_report_summary( if filters.get("accumulated_in_group_company"): period_list = get_filtered_list_for_consolidated_report(filters, period_list) - for period in period_list: - key = period if consolidated else period.key + if filters.accumulated_values: + # when 'accumulated_values' is enabled, periods have running balance. + # so, last period will have the net amount. + key = period_list[-1].key if income: - net_income += income[-2].get(key) + net_income = income[-2].get(key) if expense: - net_expense += expense[-2].get(key) + net_expense = expense[-2].get(key) if net_profit_loss: - net_profit += net_profit_loss.get(key) + net_profit = net_profit_loss.get(key) + else: + for period in period_list: + key = period if consolidated else period.key + if income: + net_income += income[-2].get(key) + if expense: + net_expense += expense[-2].get(key) + if net_profit_loss: + net_profit += net_profit_loss.get(key) if len(period_list) == 1 and periodicity == "Yearly": profit_label = _("Profit This Year")