[v7] Timesheet billing workflow enhancement (list view to invoice)

I’m trying to add a function from the Timesheet list view that would act just like the “Make Time Log Batch” menu item in v6. So not being very capable of writing anything, I stole the snippet. (yes there are still residual terms and functions that have to be removed)

			// select only billable timesheets
			for(var i in selected) {
				var d = selected[i];
				//if(!d.billable) {
				//	msgprint(__("Timesheet is not billable") + ": " + d.name + " - " + d.title);
				//	return;
				if(d.status=="Batched for Billing") {
					msgprint(__("Timesheet has been Batched for Billing") + ": " + d.name + " - " + d.title);
				if(d.status=="Billed") {
					msgprint(__("Timesheet has been Billed") + ": " + d.name + " - " + d.title);
				if(d.status!="Submitted") {
					msgprint(__("Timesheet Status must be Submitted.") + ": " + d.name + " - " + d.title);

			// make invoice
			frappe.model.with_doctype("Sales Invoice", function() {
				var sinv = frappe.model.get_new_doc("Sales Invoice");
				$.each(selected, function(i, d) {
					var detail = frappe.model.get_new_doc("Sales Invoice Timesheet", sinv,

					$.extend(detail, {
						"time_sheet": d.name,
						"billing_hours": d.total_billing_hours,
						"billing_amount": d.total_billing_amount
				frappe.set_route("Form", "Sales Invoice", sinv.name);

		}, "icon-file-alt");

The problem is that when it enters the timesheet, the name shows up as the Timesheet, but not as a link, just text, and the other fields don’t populate.

Is there anything that needs to be called from sales_invoice.js or sales_invoice_timesheet.js? or a method in either .py?

Any help would be greatly appreciated. Thanks



detail = frappe.model.add_child(sinv, "Sales Invoice Timesheet", "timesheets")

instead of new_doc

Thanks for the reply! Really excited to have this working as a replacement for batching.

I tried your suggestion as shown. but to no difference in operation. Nothing in the console, and the screenshot of the result would remain the same unfortunately. It does calculate once saved, and I wonder that if we instead use a recalculation method? I’ve tried to call (via client script) some of the recalculate methods in the sales_invoice.py, but haven’t had any luck.

I’ll continue trying to make sense of it, but as always, your help is great!! Thanks