Sales Invoice list onload does not fire

I can sucessfully hook into onload events for almost all doctypes. For example the following code works fine

frappe.listview_settings['Account'] = {
    onload: function (listview) {
        console.log('the account list view loads') // works fine :-)
    }
};

however the Sales Invoice list event hook does not fire

frappe.listview_settings['Sales Invoice'] = {
    onload: function (listview) {
        console.log('the sales invoice list view loads') // doesn't fire :-(
    }
};

I think the reason may be because Sales Invoice does already have an onload event hook defined in its own erpnext sales_invoice_list.js file?

How can I hook into the Sales Invoice list load event in my own, custom code?

Hi @chrislennon:

Search “Installed Applications” on search bar.
Use “Update Hooks Resolution Order”

https://frappeframework.com/docs/user/en/python-api/hooks#how-are-conflicting-hooks-resolved-

Hope this helps.

Thanks, but the problem remains no matter what order by custom app appears in this list

Hi @chrislennon:

Oh, sorry, it will work for backend methods, not client …

For .js you will to extend … check it:

1 Like

Thank you. This is exactly what I am looking to do. Extend the onload event of the Sales Invoice listview. However for some reason its still not firing!

I used the code from @snv and just changed the document name to Sales Invoice. That is the only change I made - so code is:

function extend_listview_event(doctype, event, callback) {

    if (!frappe.listview_settings[doctype]) {
        frappe.listview_settings[doctype] = {};
    }

    const old_event = frappe.listview_settings[doctype][event];
    frappe.listview_settings[doctype][event] = function (listview) {
        if (old_event) {
            old_event(listview);
        }
        callback(listview);
    }
}

extend_listview_event("Sales Invoice", "onload", function (listview) {
     console.log ('Sales invoice onload event') //still doesn't fire :-(
});

Hoping someone can help me solve this one!

@chrislennon,

Provided code worked properly, please check it.

1 Like

Thanks all, really appreciate all the help on this. I am learning some things and hopefully we are creating some clarity for anyone who reads this thread

I copied and pasted my code into the script editor as per the video, and yes it does work :slight_smile: The difference is that I am not using the script editor, rather I am using my own javascript file that I link up in hooks.py. I.e. in hooks.py I have app_include_js = "/assets/erp/js/erp.js" (my custom app is just called “erp” at the moment) and then I have the code in erp.js. This is where it doesn’t fire, so there must be a suble difference between the way custom scripts you save in the UI work, and the same javascript in regular code.

I can probably use a UI based custom script as a work-around although it won’t be a neat solution. For comepleteness it would be nice to know if the Sales Invoice list can be customised using app-wide script, even if its over-riding not extending

It is wrong; please check it.

if you want to apply for the listview script then apply it in the hooks

doctype_list_js = {"Sales Invoice" : "public/js/sales_invoice_list.js"}

then build the app and migrate the site.

1 Like