An employee can also be a leave approver. In that case he/she is able to select Approved/Rejected for Status. How come they self-approve their leave? They should be only select Approved/Rejected when they are approving/rejecting subordinates leave requests. How can I configure this?
Hi,
Please use the following client script to block the same:
frappe.ui.form.on('Leave Application', {
validate: function(frm) {
// Check if the current user is the owner of the document
if (frm.doc.owner === frappe.session.user) {
// If owner, prevent changing the status field
if (frm.doc.status !== frm.doc.__onload?.status) { // Check if status has changed
frappe.throw(__('You are not allowed to change the status of your own Leave Application.'));
}
}
}
});
Thanks,
Divyesh Mangroliya
Where should I run or use this script? Clear instructions please.
There’s a caveat in the code, it is blocking employee from applying leave itself, by keeping Status in Open state. Can you check once again?
Even admin is not able to apply, leave on behalf of the Employee. @mangroliya
Hi,
Script will not allow to change the status to the creator. Status can only be changed by another person, in your case it should be leave approver.
While creating leave applications users should not touch the status field. If HR is creating leave on behalf of employee and HR is leave approver, this script will not allow her to approve that document.
Hope, this is what you want. If you need something else, please let me know.
Thanks,
Divyesh M.
Yes, if I am leave approver, I shouldn’t approve my own leave request. Your code is blocking from applying leave at all.
Hi,
Please change the script will following and try. I am assuming while users applying leave, they are keeping staus ‘Open’ only.
frappe.ui.form.on('Leave Application', {
validate: function(frm) {
// Check if the current user is the owner of the document
if (frm.doc.owner === frappe.session.user) {
// If owner, prevent changing the status field
if (frm.doc.status !== 'Open') { // Check if status has changed
frappe.throw(__('You are not allowed to change the status of your own Leave Application.'));
}
}
}
});
Thanks,
Divyesh Mangroliya
On Version v15.39.0 (Release v15.39.0 · frappe/hrms · GitHub)
Added a new setting in HR Settings called Prevent self-approval for leaves even if user has permissions
Nope, not working
Can you spot it, in the below screenshot?
ERPNext: v14.56.0 (version-14)
Frappe Framework: v14.60.0 (version-14)
Frappe HR: v16.0.0-dev (develop)
Hi,
Can you share the screenshot of the Leave Application, which employees are filling in?
Thanks,
Divyesh Mangroliya
This works thanks. I forgot to enable it previously.