How to link Expense Claims to Sales Invoice

Hello everyone, I’m trying to modify the Sales Invoice to have a similar functionality to Timesheet (Activity Cost).

I have employees who can submit expense claims against a project (I’ve added the project link to the expense doctype). I’ve created a relational doctype (Sales Invoice Expense Claim) (similar to Sales Invoice Timesheet). For forum is updated and I can see Sales Invoice, but now comes to the hard part where I would like to add a button to “Fetch Expenses”. I can’t seem to find anything related to how to add a button.

Any suggestion or advice will be greatly appreciated.

Hi @jf888,

Please check the scenario and then apply the client script for it.

Client Script Code:

frappe.ui.form.on('Sales Invoice', {
    refresh: function (frm) {
        frm.add_custom_button(__('Get Expense Claims'), function () {
            new frappe.ui.form.MultiSelectDialog({
                doctype: "Expense Claim",
                size: 'large',
                target: frm,
                setters: [{
                        label: ('Status'),
                        fieldname: 'status',
                        fieldtype: 'Select',
                        options: '\nDraft\nPaid\nUnpaid\nRejected\nSubmitted\nCancelled',
                        label: ('Project'),
                        fieldname: 'project',
                        fieldtype: 'Link',
                        options: "Project",
                        default: frm.doc.project
                        label: ('Total Claimed Amount'),
                        fieldname: 'total_claimed_amount',
                        fieldtype: 'Currency',
                        hidden: 1
                        label: ('Total Sanctioned Amount'),
                        fieldname: 'total_sanctioned_amount',
                        fieldtype: 'Currency',
                        hidden: 1
                get_query() {
                    return {
                        filters: {}
                action(selections) {
                    if (selections && selections.length > 0) {
                        $.each(selections, function (i, expense_claim) {
                            frm.add_child("sales_invoice_expense_claim", {
                                expense_claim: expense_claim,

Please set your field according.

I hope this helps.

Thank You!

1 Like

Thanks for the reply. I will definitely give this a spin today.

@NCP this worked perfectly.

Thank you!!!