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

fix: filters on vehicle expenses report (backport #2440) #2447

Merged
Merged
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
23 changes: 20 additions & 3 deletions hrms/hr/report/vehicle_expenses/vehicle_expenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ frappe.query_reports["Vehicle Expenses"] = {
options: ["Fiscal Year", "Date Range"],
default: ["Fiscal Year"],
reqd: 1,
on_change: () => {
let filter_based_on = frappe.query_report.get_filter_value("filter_based_on");

if (filter_based_on == "Fiscal Year") {
set_reqd_filter("fiscal_year", true);
set_reqd_filter("from_date", false);
set_reqd_filter("to_date", false);
}
if (filter_based_on == "Date Range") {
set_reqd_filter("fiscal_year", false);
set_reqd_filter("from_date", true);
set_reqd_filter("to_date", true);
}
},
},
{
fieldname: "fiscal_year",
Expand All @@ -17,21 +31,18 @@ frappe.query_reports["Vehicle Expenses"] = {
options: "Fiscal Year",
default: frappe.defaults.get_user_default("fiscal_year"),
depends_on: "eval: doc.filter_based_on == 'Fiscal Year'",
reqd: 1,
},
{
fieldname: "from_date",
label: __("From Date"),
fieldtype: "Date",
reqd: 1,
depends_on: "eval: doc.filter_based_on == 'Date Range'",
default: frappe.datetime.add_months(frappe.datetime.nowdate(), -12),
},
{
fieldname: "to_date",
label: __("To Date"),
fieldtype: "Date",
reqd: 1,
depends_on: "eval: doc.filter_based_on == 'Date Range'",
default: frappe.datetime.nowdate(),
},
Expand All @@ -49,3 +60,9 @@ frappe.query_reports["Vehicle Expenses"] = {
},
],
};

function set_reqd_filter(fieldname, is_reqd) {
let filter = frappe.query_report.get_filter(fieldname);
filter.df.reqd = is_reqd;
filter.refresh();
}
Loading