mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-24 15:39:20 +00:00
fix: hot path in page load
This commit is contained in:
@@ -267,11 +267,10 @@ function get_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);
|
||||
let fiscal_year = erpnext.utils.get_fiscal_year(frappe.datetime.get_today(), false, false);
|
||||
if (fiscal_year) {
|
||||
let fy = erpnext.utils.get_fiscal_year(frappe.datetime.get_today(), false, false);
|
||||
fy_filters.forEach((x) => {
|
||||
x.default = fy;
|
||||
x.default = fiscal_year;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -420,7 +420,7 @@ $.extend(erpnext.utils, {
|
||||
});
|
||||
},
|
||||
|
||||
get_fiscal_year: function (date, with_dates = false, boolean = false) {
|
||||
get_fiscal_year: function (date, with_dates = false, raise_on_missing = true) {
|
||||
if (!frappe.boot.setup_complete) {
|
||||
return;
|
||||
}
|
||||
@@ -429,20 +429,30 @@ $.extend(erpnext.utils, {
|
||||
}
|
||||
|
||||
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 {
|
||||
frappe.call({
|
||||
method: "erpnext.accounts.utils.get_fiscal_year",
|
||||
type: "GET", // make it cacheable
|
||||
args: {
|
||||
date: date,
|
||||
raise_on_missing: raise_on_missing,
|
||||
},
|
||||
async: false,
|
||||
callback: function (r) {
|
||||
if (r.message) {
|
||||
if (with_dates) fiscal_year = r.message;
|
||||
else fiscal_year = r.message[0];
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
return fiscal_year;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user