From e2dd414793d357272494f0a7f03d1d0c1e6452b0 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 14 Nov 2023 06:44:49 +0530 Subject: [PATCH] refactor: use 'boolean' parameter while fetching FY year (cherry picked from commit c31ee8ea33afcc8128270f098c40cc0b0e3f1a49) --- erpnext/accounts/utils.py | 3 +++ erpnext/public/js/financial_statements.js | 10 ++++++++-- erpnext/public/js/utils.js | 5 +++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 8ae6c0e082d7..4abd04b6c218 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -53,6 +53,9 @@ class PaymentEntryUnlinkError(frappe.ValidationError): def get_fiscal_year( date=None, fiscal_year=None, label="Date", verbose=1, company=None, as_dict=False, boolean=False ): + if isinstance(boolean, str): + boolean = frappe.json.loads(boolean) + fiscal_years = get_fiscal_years( date, fiscal_year, label, verbose, company, as_dict=as_dict, boolean=boolean ) diff --git a/erpnext/public/js/financial_statements.js b/erpnext/public/js/financial_statements.js index 907a775bfa53..1b10d8ad3a17 100644 --- a/erpnext/public/js/financial_statements.js +++ b/erpnext/public/js/financial_statements.js @@ -139,7 +139,6 @@ function get_filters() { "label": __("Start Year"), "fieldtype": "Link", "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), "reqd": 1, "depends_on": "eval:doc.filter_based_on == 'Fiscal Year'" }, @@ -148,7 +147,6 @@ function get_filters() { "label": __("End Year"), "fieldtype": "Link", "options": "Fiscal Year", - "default": erpnext.utils.get_fiscal_year(frappe.datetime.get_today()), "reqd": 1, "depends_on": "eval:doc.filter_based_on == 'Fiscal Year'" }, @@ -197,5 +195,13 @@ function get_filters() { } ] + // Dynamically set 'default' values for fiscal year filters + let fy_filters = filters.filter(x=>{return ["from_fiscal_year", "to_fiscal_year"].includes(x.fieldname);}) + let fiscal_year = erpnext.utils.get_fiscal_year(frappe.datetime.get_today(), false, true); + if (fiscal_year) { + let fy = erpnext.utils.get_fiscal_year(frappe.datetime.get_today(), false, false); + fy_filters.forEach(x=>{x.default = fy;}) + } + return filters; } diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index d435711cf52a..25fc754b9ae1 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -404,7 +404,7 @@ $.extend(erpnext.utils, { }); }, - get_fiscal_year: function(date, with_dates=false) { + get_fiscal_year: function(date, with_dates=false, boolean=false) { if(!date) { date = frappe.datetime.get_today(); } @@ -413,7 +413,8 @@ $.extend(erpnext.utils, { frappe.call({ method: "erpnext.accounts.utils.get_fiscal_year", args: { - date: date + date: date, + boolean: boolean }, async: false, callback: function(r) {