Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use 'boolean' parameter while fetching FY year #38082

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
10 changes: 8 additions & 2 deletions erpnext/public/js/financial_statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
},
Expand All @@ -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'"
},
Expand Down Expand Up @@ -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;
}
5 changes: 3 additions & 2 deletions erpnext/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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) {
Expand Down