Autoselect Customer and Project while creating timesheet

Hi,

I created a new project and selected a customer.
When I open the project and create a timesheet, the customer and project is not automatically selected. User has to do the selection manually which is prone to errors.

How can I ensure that the customer and project is automatically selected?

Satish Gupta

Hi @sguptajpr

In ERPNext does not automatically select the customer and project in a timesheet based on the project selection.

Thanks for replying.
But it does everywhere else. Why not projects?
Is there any way we can customize form to do so?

If you are trying to use the + icon to create a timesheet from a project, and the project and customer details are not set, then you have to apply the client script in the project doctype.

frappe.ui.form.on('Project', {
	setup: function(frm) {
	    frm.custom_make_buttons = {
			"Timesheet Link": "Timesheet",
		};
		frm.make_methods = {
            "Timesheet Link": () =>
			frappe.model.with_doctype("Timesheet", function () {
				var ts = frappe.model.get_new_doc("Timesheet");
				ts.project = frm.doc.name;
				ts.customer = frm.doc.customer;
				frappe.set_route("Form", "Timesheet", ts.name);
			}),
		};
	}
});

Then reload Ctrl+Shift+R and check it.

1 Like

Amazing. It worked.
Thanks for such a quick and ‘to the point’ answer