diff --git a/hrms/hr/doctype/leave_application/leave_application.py b/hrms/hr/doctype/leave_application/leave_application.py index 2f8ad9fa02..fc47cff472 100755 --- a/hrms/hr/doctype/leave_application/leave_application.py +++ b/hrms/hr/doctype/leave_application/leave_application.py @@ -796,11 +796,13 @@ 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"] - and not get_workflow_name("Leave Application") + self.employee == get_current_employee_info().get("name") + if get_current_employee_info() + else None and not get_workflow_name("Leave Application") ): - frappe.throw(_("Self approval for leaves is not allowed"), frappe.ValidationError) + frappe.throw(_("Self-approval for leaves is not allowed"), frappe.ValidationError) def get_allocation_expiry_for_cf_leaves( diff --git a/hrms/hr/doctype/leave_application/test_leave_application.py b/hrms/hr/doctype/leave_application/test_leave_application.py index d522dc4902..4c0b1ef302 100644 --- a/hrms/hr/doctype/leave_application/test_leave_application.py +++ b/hrms/hr/doctype/leave_application/test_leave_application.py @@ -1005,6 +1005,8 @@ def test_self_leave_approval_allowed(self): self.assertEqual(1, application.docstatus) + frappe.set_user("Administrator") + def test_self_leave_approval_not_allowed(self): frappe.db.set_single_value("HR Settings", "allow_self_leave_approval", 0)