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 #2440

Merged
Merged
Changes from 2 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_filter_requirement("fiscal_year", true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set_filter_requirement("fiscal_year", true);
set_reqd_filter("fiscal_year", true);

Call this set_reqd_filter instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

set_filter_requirement("from_date", false);
set_filter_requirement("to_date", false);
}
if (filter_based_on == "Date Range") {
set_filter_requirement("fiscal_year", false);
set_filter_requirement("from_date", true);
set_filter_requirement("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_filter_requirement(fieldname, is_reqd) {
let filter = frappe.query_report.get_filter(fieldname);
filter.df.reqd = is_reqd;
filter.refresh();
}
Loading