Skip to content

Commit

Permalink
fix: ignore the self-approval setting a workfow is active on Leave Ap…
Browse files Browse the repository at this point in the history
…plication
  • Loading branch information
asmitahase committed Jan 30, 2025
1 parent 525fcdd commit 7653c51
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 7 additions & 4 deletions hrms/hr/doctype/leave_application/leave_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ frappe.ui.form.on("Leave Application", {
if (frm.doc.leave_approver) {
frm.set_value("leave_approver_name", frappe.user.full_name(frm.doc.leave_approver));
}
frm.trigger("prevent_self_leave_approval");
},

leave_type: function (frm) {
Expand Down Expand Up @@ -257,17 +258,19 @@ frappe.ui.form.on("Leave Application", {
}
},

leave_approver: function (frm) {
frm.trigger("prevent_self_leave_approval");
},
prevent_self_leave_approval: async function (frm) {
let is_invalid_leave_approver = invalid_leave_approver(
frm.doc.employee,
await hrms.get_current_employee(),
await self_approval_not_allowed(),
);

if (frm.doc.docstatus === 0 && is_invalid_leave_approver && !frm.is_dirty()) {
if (
frm.doc.docstatus === 0 &&
is_invalid_leave_approver &&
!frm.is_dirty() &&
!frappe.model.has_workflow(frm.doctype)
) {
frm.page.clear_primary_action();
$(".form-message").prop("hidden", true);
}
Expand Down
6 changes: 5 additions & 1 deletion hrms/hr/doctype/leave_application/leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import frappe
from frappe import _
from frappe.model.workflow import get_workflow_name
from frappe.query_builder.functions import Max, Min, Sum
from frappe.utils import (
add_days,
Expand Down Expand Up @@ -797,7 +798,10 @@ def create_ledger_entry_for_intermediate_allocation_expiry(self, expiry_date, su

def validate_for_self_approval(self):
self_leave_approval_allowed = frappe.db.get_single_value("HR Settings", "allow_self_leave_approval")
if (not self_leave_approval_allowed) and (self.employee == get_current_employee_info()["name"]):
if (not self_leave_approval_allowed) and (
self.employee == get_current_employee_info()["name"]
and not get_workflow_name("Leave Application")
):
frappe.throw(_("Self approval for leaves is not allowed"), frappe.ValidationError)


Expand Down

0 comments on commit 7653c51

Please sign in to comment.