From 4274c2aba390348a9786fa99a9f53be7b64416d1 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Thu, 23 Apr 2026 16:29:38 +0530 Subject: [PATCH] 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.