From 5a915cb45e872b45919b6311b9b29037abd5d239 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Thu, 23 Apr 2026 15:43:20 +0530 Subject: [PATCH 1/5] fix: ensure fiscal year is checked before validating date filters in financial statements --- erpnext/public/js/financial_statements.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/public/js/financial_statements.js b/erpnext/public/js/financial_statements.js index 0c8366d4e95..a656eb57118 100644 --- a/erpnext/public/js/financial_statements.js +++ b/erpnext/public/js/financial_statements.js @@ -298,7 +298,7 @@ erpnext.financial_statements = { let fiscal_year = erpnext.utils.get_fiscal_year(frappe.datetime.get_today()); var filters = report.get_values(); - if (!filters.period_start_date || !filters.period_end_date) { + if (fiscal_year && (!filters.period_start_date || !filters.period_end_date)) { frappe.model.with_doc("Fiscal Year", fiscal_year, function (r) { var fy = frappe.model.get_doc("Fiscal Year", fiscal_year); frappe.query_report.set_filter_value({ From 79d6a51e1eb83b341ee92d52c8b2f0e1e2532b48 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Thu, 23 Apr 2026 15:54:42 +0530 Subject: [PATCH 2/5] fix: update fiscal year filter to use mandatory_depends_on instead of reqd --- erpnext/public/js/financial_statements.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/financial_statements.js b/erpnext/public/js/financial_statements.js index a656eb57118..faadb6f8235 100644 --- a/erpnext/public/js/financial_statements.js +++ b/erpnext/public/js/financial_statements.js @@ -422,16 +422,16 @@ function get_filters() { label: __("Start Year"), fieldtype: "Link", options: "Fiscal Year", - reqd: 1, depends_on: "eval:doc.filter_based_on == 'Fiscal Year'", + mandatory_depends_on: "eval:doc.filter_based_on == 'Fiscal Year'", }, { fieldname: "to_fiscal_year", label: __("End Year"), fieldtype: "Link", options: "Fiscal Year", - reqd: 1, depends_on: "eval:doc.filter_based_on == 'Fiscal Year'", + mandatory_depends_on: "eval:doc.filter_based_on == 'Fiscal Year'", }, { fieldname: "periodicity", From 4274c2aba390348a9786fa99a9f53be7b64416d1 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Thu, 23 Apr 2026 16:29:38 +0530 Subject: [PATCH 3/5] fix: add filter labels and required filters for financial report validation --- .../financial_report_engine.py | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/financial_report_template/financial_report_engine.py b/erpnext/accounts/doctype/financial_report_template/financial_report_engine.py index b5bd3a00a9f..1e1762041cd 100644 --- a/erpnext/accounts/doctype/financial_report_template/financial_report_engine.py +++ b/erpnext/accounts/doctype/financial_report_template/financial_report_engine.py @@ -203,6 +203,21 @@ class FormattingRule: # ============================================================================ +FILTER_LABELS = { + "report_template": _("Report Template"), + "filter_based_on": _("Filter Based On"), + "period_start_date": _("Start Date"), + "period_end_date": _("End Date"), + "from_fiscal_year": _("Start Year"), + "to_fiscal_year": _("End Year"), +} + +REQUIRED_FILTERS_BY_BASIS = { + "Date Range": ("period_start_date", "period_end_date"), + "Fiscal Year": ("from_fiscal_year", "to_fiscal_year"), +} + + class FinancialReportEngine: def execute(self, filters: dict[str, Any]) -> tuple[list[dict], list[dict]]: """Execute the complete report generation""" @@ -222,14 +237,24 @@ class FinancialReportEngine: return context.get_result() def _validate_filters(self, filters: dict[str, Any]) -> None: - required_filters = ["report_template", "period_start_date", "period_end_date"] + required_filters = ["report_template", "filter_based_on"] + required_filters.extend(REQUIRED_FILTERS_BY_BASIS.get(filters.get("filter_based_on"), ())) for filter_key in required_filters: if not filters.get(filter_key): - frappe.throw(_("Missing required filter: {0}").format(filter_key)) + frappe.throw( + title=_("Missing Required Filter"), + msg=_("Missing required filter: {0}").format( + frappe.bold(FILTER_LABELS.get(filter_key, filter_key)) + ), + ) if filters.get("presentation_currency"): - frappe.msgprint(_("Currency filters are currently unsupported in Custom Financial Report.")) + frappe.msgprint( + title=_("Unsupported Feature"), + msg=_("Currency filters are currently unsupported in Custom Financial Report."), + indicator="orange", + ) # Margin view is dependent on first row being an income account. Hence not supported. # Way to implement this would be using calculated rows with formulas. From 1fd6c3ba1a847720b18bb884164dd200b1fbfa26 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Thu, 23 Apr 2026 17:05:33 +0530 Subject: [PATCH 4/5] fix: update account identification to avoid using name_field in financial statements --- erpnext/public/js/financial_statements.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/public/js/financial_statements.js b/erpnext/public/js/financial_statements.js index faadb6f8235..811644b48b7 100644 --- a/erpnext/public/js/financial_statements.js +++ b/erpnext/public/js/financial_statements.js @@ -64,7 +64,7 @@ erpnext.financial_statements = { const isPeriodColumn = periodKeys.includes(baseName); return { - isAccount: baseName === erpnext.financial_statements.name_field, + isAccount: baseName === "account", // DO NOT USE `name_field` ! This can be overridden in some reports! isPeriod: isPeriodColumn, segmentIndex: valueMatch && valueMatch[1] ? parseInt(valueMatch[1]) : null, fieldname: baseName, From 3854d2cbf6dfef8aecdc1ddb3876e49d35b32c57 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Thu, 23 Apr 2026 17:13:01 +0530 Subject: [PATCH 5/5] chore: minor fix --- .../financial_report_engine.py | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/erpnext/accounts/doctype/financial_report_template/financial_report_engine.py b/erpnext/accounts/doctype/financial_report_template/financial_report_engine.py index 1e1762041cd..7938a0eaef5 100644 --- a/erpnext/accounts/doctype/financial_report_template/financial_report_engine.py +++ b/erpnext/accounts/doctype/financial_report_template/financial_report_engine.py @@ -203,21 +203,6 @@ class FormattingRule: # ============================================================================ -FILTER_LABELS = { - "report_template": _("Report Template"), - "filter_based_on": _("Filter Based On"), - "period_start_date": _("Start Date"), - "period_end_date": _("End Date"), - "from_fiscal_year": _("Start Year"), - "to_fiscal_year": _("End Year"), -} - -REQUIRED_FILTERS_BY_BASIS = { - "Date Range": ("period_start_date", "period_end_date"), - "Fiscal Year": ("from_fiscal_year", "to_fiscal_year"), -} - - class FinancialReportEngine: def execute(self, filters: dict[str, Any]) -> tuple[list[dict], list[dict]]: """Execute the complete report generation""" @@ -237,15 +222,29 @@ class FinancialReportEngine: return context.get_result() def _validate_filters(self, filters: dict[str, Any]) -> None: + filter_labels = { + "report_template": _("Report Template"), + "filter_based_on": _("Filter Based On"), + "period_start_date": _("Start Date"), + "period_end_date": _("End Date"), + "from_fiscal_year": _("Start Year"), + "to_fiscal_year": _("End Year"), + } + + required_filters_by_basis = { + "Date Range": ("period_start_date", "period_end_date"), + "Fiscal Year": ("from_fiscal_year", "to_fiscal_year"), + } + required_filters = ["report_template", "filter_based_on"] - required_filters.extend(REQUIRED_FILTERS_BY_BASIS.get(filters.get("filter_based_on"), ())) + required_filters.extend(required_filters_by_basis.get(filters.get("filter_based_on"), ())) for filter_key in required_filters: if not filters.get(filter_key): frappe.throw( title=_("Missing Required Filter"), msg=_("Missing required filter: {0}").format( - frappe.bold(FILTER_LABELS.get(filter_key, filter_key)) + frappe.bold(filter_labels.get(filter_key, filter_key)) ), )