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 46369b07cd9..4ea86e2c1f4 100644 --- a/erpnext/accounts/doctype/financial_report_template/financial_report_engine.py +++ b/erpnext/accounts/doctype/financial_report_template/financial_report_engine.py @@ -226,14 +226,38 @@ 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"] + 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"), ())) 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. diff --git a/erpnext/public/js/financial_statements.js b/erpnext/public/js/financial_statements.js index cdfb8f8a2ca..95a4dcc0d17 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, @@ -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({ @@ -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",