Add fields to Sales Invoice Timesheets

I’m unable to link extra fields to sales invoice timesheets.

How do I link for example ‘task_name’ from timesheet detail?

Any help really appreciated.

Hi @bedo

Check below code, you need to pass the extra parameter in the dictionary

hi @rohit_w,

that code seems to run on a server side as python? So are you suggesting modifying source code? I would like to resolve my problem using custom script.

Is there an option how to fetch extra child fields without changing the source code?

Hi @bedo

For custom script, you need to use frappe.client.get_value. For more details kindly refer below code

Hi @rohit_w,
could you help me a bit with the code?
this doesn’t work…but it can’t be too far :wink:

frappe.ui.form.on("Sales Invoice", "time_sheet", function(frm) {
var child = locals[cdt][cdn];
    cur_frm.call({
        "method": "frappe.client.get_value",
        "args": {
            "doctype": "Timesheet Detail",
            "filters": {
                "name":  child.task_name
            }
        },
        "child": child,
        "fieldname": "task_name"

});

Instead of this use “parent”: child.time_sheet and you also required one more filter of the child table

Dear @rohit_w,

I don’t fully understand how this code should work. In its current form it throws an error.

frappe.ui.form.on("Sales Invoice", "onload", function(frm, cdt, cdn) {
var child = locals[cdt][cdn];
    frappe.call({
        "method": "frappe.client.get_value",
        "args": {
            "doctype": "Timesheet Detail",
            "filters": {
                "parent": child.time_sheet
            }
        },
        "child": child,
        "fieldname": "task_name"
	})
});

I’ve also found this piece of code, but it doesn’t work either:

I thought I could just change ‘Sales Invoice Timesheet’ to ‘Sales Invoice’ and instead of:

{
data = r.message;
frappe.model.set_value(cdt, cdn, "billing_hours", data.billing_hours);
frappe.model.set_value(cdt, cdn, "billing_amount", data.billing_amount);
frappe.model.set_value(cdt, cdn, "timesheet_detail", data.timesheet_detail);
calculate_total_billing_amount(frm)
}

I tried:

{
data = r.message;
frappe.model.set_value(cdt, cdn, "task_name", data.task_name);
}

But nothing gives me any results:( I’m hopeless…
I put this field in Sales Invoice Timesheet using Customize Form:

and this one is in Timesheet Detail:

I don’t know what I’m doing wrong.