How to Add a column to Sales invoice list view From another doctype

I Installed a custom app called ksa_compliance and there is a Doctype called ‘Sales Invoice Additional Fields’ and this is populated when the sale invoice is submitted and then it goes to ZATCA (for clearance purposes) and Sales Invoice Additional Fields get populated.

Now in the Sales Invoice Additional Fields there is a field named as integration_status which has the following values

Ready For Batch
Resend
Corrected
Accepted with warnings
Accepted
Rejected
Clearance switched off

and another field called sales_invoice in which there is sales invoice number.

So I want to show this integration_status in Sales invoice list view and tried a lot of this but non of them are working.

I have tried client script but exactly don’t know how to add this to the list view.

Why do creating a complexity, simply add the custom field in the sales invoice, get the data from another doctype, and set it as a listview

Yes but the problem is, that this field is only created when it is send to zatca and get a status value. if I create a custom field then I don’t know when to populate this field.

Here I added a dynamic scenario for Item Listview, i get the total stock qty in the listview with the dynamic row. so you can check it.

ListView Client Script:

frappe.listview_settings['Item'] = {
    refresh: function(listview) {
        frappe.call({
            method: "frappe.client.get_list",
            args: {
                doctype: "Bin",
                fields: ["item_code", "actual_qty", "warehouse"],
                limit_page_length: 1000
            },
            callback: function(response) {
                let stock_data = {};
                response.message.forEach(function(bin) {
                    if (!stock_data[bin.item_code]) {
                        stock_data[bin.item_code] = 0;
                    }
                    stock_data[bin.item_code] += bin.actual_qty || 0;
                });

                if (listview.$result.find('.list-row-head .list-row-col:contains("Stock Qty")').length === 0) {
                    listview.$result.find('.list-row-head .list-row-col:last').each(function() {
                        $('<div class="list-row-col ellipsis hidden-xs"><span>Stock Qty</span></div>').insertAfter($(this));
                    });
                }

                listview.$result.find('.list-row-container .list-row').each(function() {
                    let $row = $(this);

                    if ($row.find('.list-row-col:contains("Stock Qty")').length === 0) {
                        let item_id = $row.find('.list-row-col:last').text().trim();
                        let stock_qty = stock_data[item_id] || 0;

                        let $stock_col = $(`<div class="list-row-col ellipsis hidden-xs"><span>${stock_qty}</span></div>`);
                        $stock_col.insertAfter($row.find('.list-row-col:last'));
                    }
                });
            }
        });
    }
};
1 Like

Thank you, I did some changes for my own columns and it worked.