kittiu
1
I want to extend the doctype list view on onload functoin, i.e., adding menu, etc.
By using hooks.py
doctype_list_js = {
“Salary Slip”: “public/js/salary_slip_list.js”,
}
However, from experiment (and by reading in this forum), the function onload is completely overwritten, which means, the core feature is gone.
AFAIK, the extending of the Form view is OK to be extended using similar method.
doctype_js = {
“Salary Slip”: “public/js/salary_slip.js”,
}
Am I correct? And are there work around for the list view?
NCP
2
Hi @kittiu,
It’s worked properly and also I checked from my end. Please check the video.
bench build --force
I hope this helps.
Thank You!
ankush
3
It’s not overridden completely, just extended.
Here’s where it happens:
1 Like
kittiu
4
But what you did is overriding also, isn’t it?
If not, now you should have 2 menus,
- Email Salary Slip → from core hr module
- Email Salary Slip | NCP → from your custom module
What you did override the one from core hr.
And so, in my case to keep the existing “Email Salary Slip” while adding a new menu, I need to duplicate the code here.
If I have more than 1 module, this is not easy to maintain.
frappe.listview_settings["Salary Slip"] = {
onload: function(listview) {
// Override apps/hrms/hrms/payroll/doctype/salary_slip/salary_slip_list.js
if (!has_common(frappe.user_roles, ["Administrator", "System Manager", "HR Manager", "HR User"])) return;
listview.page.add_menu_item(__("Email Salary Slips"), () => {
if (!listview.get_checked_items().length) {
frappe.msgprint(__("Please select the salary slips to email"));
return;
}
frappe.confirm(__("Are you sure you want to email the selected salary slips?"), () => {
listview.call_for_selected_items("hrms.payroll.doctype.salary_slip.salary_slip.enqueue_email_salary_slips");
});
});
// --
// Addition
listview.page.add_action_item(__("Withholding Tax Cert Employee"), ()=>{
erpnext.bulk_transaction_processing.create(
listview,
"Salary Slip",
"Withholding Tax Cert Employee"
);
});
}
};
If this is the only solution, I would not say it is extendable (but override-able).
Please proof me wrong.
snv
5
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("Salary Slip", "onload", function (listview) {
// your code here
});
Hope this helps
5 Likes
kittiu
6
Thank you, this works! These kind of tricks should be collected into a cheat sheet !
1 Like