Skip to content

Commit

Permalink
fix: filters on vehicle expenses report (backport #2440) (#2446)
Browse files Browse the repository at this point in the history
Co-authored-by: Asmita Hase <[email protected]>
  • Loading branch information
mergify[bot] and asmitahase authored Nov 25, 2024
1 parent 8058d74 commit 6d35f11
Showing 1 changed file with 20 additions and 3 deletions.
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();
}

0 comments on commit 6d35f11

Please sign in to comment.