From 685132236128456fe9ed5e3677454f92cc631e08 Mon Sep 17 00:00:00 2001 From: ljain112 Date: Thu, 24 Apr 2025 19:32:38 +0530 Subject: [PATCH 1/4] fix: accumulate values for all the fiscal years in Profit And Loss Statement --- .../profit_and_loss_statement/profit_and_loss_statement.py | 2 -- 1 file changed, 2 deletions(-) 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 2b6280c74b5..ccb4d26f77b 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 @@ -35,7 +35,6 @@ def execute(filters=None): filters=filters, accumulated_values=filters.accumulated_values, ignore_closing_entries=True, - ignore_accumulated_values_for_fy=True, ) expense = get_data( @@ -46,7 +45,6 @@ def execute(filters=None): filters=filters, accumulated_values=filters.accumulated_values, ignore_closing_entries=True, - ignore_accumulated_values_for_fy=True, ) net_profit_loss = get_net_profit_loss( From 61d13ce232c25122ac9a47104ccae0a23aea5f69 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 12 May 2025 15:07:02 +0530 Subject: [PATCH 2/4] fix: typo --- .../profit_and_loss_statement/test_profit_and_loss_statement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py index 7e2d4a7afe0..c9dfe515a08 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py +++ b/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py @@ -58,7 +58,7 @@ class TestProfitAndLossStatement(AccountsTestMixin, IntegrationTestCase): period_end_date=fy.year_end_date, filter_based_on="Fiscal Year", periodicity="Monthly", - accumulated_vallues=True, + accumulated_values=True, ) def test_profit_and_loss_output_and_summary(self): From afff6b84ce3c86e3a3621df1efc771adb59d02ed Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 12 May 2025 15:48:39 +0530 Subject: [PATCH 3/4] test: accumulate filter on P&L report --- .../test_profit_and_loss_statement.py | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py index c9dfe515a08..c2bb11b8f47 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py +++ b/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py @@ -4,7 +4,7 @@ import frappe from frappe.desk.query_report import export_query from frappe.tests import IntegrationTestCase -from frappe.utils import getdate, today +from frappe.utils import add_days, getdate, today from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.financial_statements import get_period_list @@ -109,3 +109,64 @@ class TestProfitAndLossStatement(AccountsTestMixin, IntegrationTestCase): sales_account = frappe.db.get_value("Company", self.company, "default_income_account") self.assertIn(sales_account, contents) + + def test_accumulate_filter(self): + # ensure 2 fiscal years + cur_fy = self.get_fiscal_year() + find_for = add_days(cur_fy.year_start_date, -1) + _x = frappe.db.get_all( + "Fiscal Year", + filters={"disabled": 0, "year_start_date": ("<=", find_for), "year_end_date": (">=", find_for)}, + )[0] + prev_fy = frappe.get_doc("Fiscal Year", _x.name) + prev_fy.append("companies", {"company": self.company}) + prev_fy.save() + + # make SI on both of them + prev_fy_si = self.create_sales_invoice(qty=1, rate=450, do_not_submit=True) + prev_fy_si.posting_date = add_days(prev_fy.year_end_date, -1) + prev_fy_si.save().submit() + income_acc = prev_fy_si.items[0].income_account + + self.create_sales_invoice(qty=1, rate=120) + + # Unaccumualted + filters = frappe._dict( + company=self.company, + from_fiscal_year=prev_fy.name, + to_fiscal_year=cur_fy.name, + period_start_date=prev_fy.year_start_date, + period_end_date=cur_fy.year_end_date, + filter_based_on="Date Range", + periodicity="Yearly", + accumulated_values=False, + ) + result = execute(filters) + columns = [result[0][2], result[0][3]] + expected = { + "account": income_acc, + columns[0].get("fieldname"): 450.0, + columns[1].get("fieldname"): 120.0, + } + actual = [x for x in result[1] if x.get("account") == income_acc] + self.assertEqual(len(actual), 1) + actual = actual[0] + for key in expected.keys(): + with self.subTest(key=key): + self.assertEqual(expected.get(key), actual.get(key)) + + # accumualted + filters.update({"accumulated_values": True}) + expected = { + "account": income_acc, + columns[0].get("fieldname"): 450.0, + columns[1].get("fieldname"): 570.0, + } + result = execute(filters) + columns = [result[0][2], result[0][3]] + actual = [x for x in result[1] if x.get("account") == income_acc] + self.assertEqual(len(actual), 1) + actual = actual[0] + for key in expected.keys(): + with self.subTest(key=key): + self.assertEqual(expected.get(key), actual.get(key)) From 54e4e7918ea54d145c732fa176eb19f42d4313d2 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 12 May 2025 16:30:24 +0530 Subject: [PATCH 4/4] refactor(test): don't default to accumulate --- .../profit_and_loss_statement/test_profit_and_loss_statement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py index c2bb11b8f47..038f78ca2f3 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py +++ b/erpnext/accounts/report/profit_and_loss_statement/test_profit_and_loss_statement.py @@ -58,7 +58,7 @@ class TestProfitAndLossStatement(AccountsTestMixin, IntegrationTestCase): period_end_date=fy.year_end_date, filter_based_on="Fiscal Year", periodicity="Monthly", - accumulated_values=True, + accumulated_values=False, ) def test_profit_and_loss_output_and_summary(self):