diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 2b6d41c2d54..5942b34158d 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -420,25 +420,36 @@ $.extend(erpnext.utils, { if (!frappe.boot.setup_complete) { return; } + const today = frappe.datetime.get_today(); if (!date) { - date = frappe.datetime.get_today(); + date = today; } let fiscal_year = ""; - frappe.call({ - method: "erpnext.accounts.utils.get_fiscal_year", - args: { - date: date, - boolean: boolean, - }, - async: false, - callback: function (r) { - if (r.message) { - if (with_dates) fiscal_year = r.message; - else fiscal_year = r.message[0]; - } - }, - }); + if ( + frappe.boot.current_fiscal_year && + date >= frappe.boot.current_fiscal_year[1] && + date <= frappe.boot.current_fiscal_year[2] + ) { + if (with_dates) fiscal_year = frappe.boot.current_fiscal_year; + else fiscal_year = frappe.boot.current_fiscal_year[0]; + } else if (today != date) { + frappe.call({ + method: "erpnext.accounts.utils.get_fiscal_year", + type: "GET", // make it cacheable + args: { + date: date, + boolean: boolean, + }, + async: false, + callback: function (r) { + if (r.message) { + if (with_dates) fiscal_year = r.message; + else fiscal_year = r.message[0]; + } + }, + }); + } return fiscal_year; }, diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py index 03cbd99f5c4..b17b6b49b6b 100644 --- a/erpnext/startup/boot.py +++ b/erpnext/startup/boot.py @@ -3,8 +3,11 @@ import frappe +from frappe.defaults import get_user_default from frappe.utils import cint +from erpnext.accounts.utils import get_fiscal_years + def boot_session(bootinfo): """boot session - send website info if guest""" @@ -53,6 +56,11 @@ def boot_session(bootinfo): ) party_account_types = frappe.db.sql(""" select name, ifnull(account_type, '') from `tabParty Type`""") + fiscal_year = get_fiscal_years( + frappe.utils.nowdate(), company=get_user_default("company"), boolean=True + ) + if fiscal_year: + bootinfo.current_fiscal_year = fiscal_year[0] bootinfo.party_account_types = frappe._dict(party_account_types) bootinfo.sysdefaults.demo_company = frappe.db.get_single_value("Global Defaults", "demo_company")