How to filter only Open Project in Timesheets

When entering data Timesheet Details, I can search in field called Projects. I know I can customize search fields in Customize Form -> Project.
At the moment I have: project_description, customer, status
Project status can be: Open, Closed, Cancelled.
How do I achieve that in the Project search field for entering Timesheet, I get only Open projects? Right now I’m getting all available projects, but I don’t want to enter timesheets agains closed or cancelled projects. With gowing number of completed (=closed) projects the filter gets bigger and difficult to read.

		frm.fields_dict['time_logs'].grid.get_field('project').get_query = function() {
			return{
				filters: {
					'company': frm.doc.company,
                    'status': ["!=", "Closed"]
				}
			}

You may have to add status in your timesheet.js filter for projects or create a custom script

hi @Pawan,
thanks for help. Here the full script, maybe it will help someone.
But I have one more question please - how do I sort the selectable fields in a form? This is really happening everywhere. In timesheets, I’d like to sort the projects by project name, but right now it seems random.
I’ve checked also Invoice and all items are also random. Any idea?

 frappe.ui.form.on("Timesheet", "onload", function(frm) {
 frm.fields_dict['time_logs'].grid.get_field('project').get_query = function(doc, cdt, cdn) {
 child = locals[cdt][cdn];
 			return{	
 		filters:[
 			['status', '!=', "Completed"]
 		]
 	}
 }
 });

Hallo,
thanks for that script - good idea to avoid a log list if there are many projects.

But in which doctiype i have to set it up?
I set up an new custom script with that, Doctype “timesheet detail” and filled in the code.
But i cannot see any result.
If i make a new timesheet, in the field “project” are also projects listed, which are completd.
Any more steps to do?
Thanks

put it in Timesheet, not Timesheet Detail. Also make sure your Project Status “closed” is in reality “Completed” That’s how I have it setup.

1 Like

Thanks a lot, it works.
Is there any snc between databases? after setup, it did not work, but now, ours later, the completed projects are not visible in the list.
fine - and why not standard in erpnext …
greets

Hi Pawan,

am I understand correctly,

  • I have to edit the frappe-bench/apps/erpnext/erpnext/projects/doctype/timesheet/timesheet.js, to modify the filters.
  • I have to execute bench update --build to rebuild the minimized javascript files

correct?

I have tried these steps, but the filter for the linked field does not change…

Thanks for the help.

You put the script into custom script doctype. Create new and select Timesheet as doctype. That’s all.

I’m keen to do a similar filter within the timesheet doctype. I’d like to filter the tasks by task type. Specifically, i’d like to filter by a task type called “WBS”. Any guidance would be appreciated. I tried the following, but it didn’t work:

 frappe.ui.form.on("Timesheet", "onload", function(frm) {
 frm.fields_dict['time_logs'].grid.get_field('task').get_query = function(doc, cdt, cdn) {
 child = locals[cdt][cdn];
 			return{	
 		filters:[
 			['type', '=', "WBS"]
 		]
 	}
 }
 });

Hi,

great script! For ERPNEXT 13 and onwards I adapted the script. The child variable was not declared so a JavaScript error was thrown. This is the new script, which works well on my installation:

frappe.ui.form.on('Timesheet', {
	refresh(frm) {
		// your code here
		 frm.fields_dict['time_logs'].grid.get_field('project').get_query = function(doc, cdt, cdn) {
 let child = locals[cdt][cdn];
 			return{	
 		filters:[
 			['status', '!=', "Completed"]
 		]
 	};
 };
	}
});

And to find out how to add a custom script, you can consult that documentation: Custom Scripts

this works for me, but how can i add multiple filters for ‘status’ (OR condition)
eg
‘status’: [!=, Cancelled],
‘status’: [!=, Completed],
‘status’: [!=, Hold]
applying multiple filters to the same field only filters the last one (eg Hold)