-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: toggle self leave approval for employees from HR settings #2486
Open
asmitahase
wants to merge
8
commits into
frappe:develop
Choose a base branch
from
asmitahase:self-leave-approval
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+132
−1
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c899d04
feat: new hr setting to enable/disable self-leave approval
asmitahase cea2902
feat: Enable/disable leave applicants from approving their own leaves…
asmitahase b7583eb
chore: tests for self leave approval
asmitahase abd6d9d
chore: remove print statements
asmitahase 3c08223
fix: ignore the self-approval setting a workfow is active on Leave Ap…
asmitahase e0b69e9
fix: let administrator approve leaves irrespective of self approval s…
asmitahase c831870
chore: fixed failing tests for self leave approval
asmitahase a015fdf
chore: fixed linter error "useless get_doc dict"
asmitahase File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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, | ||||||||||||||||||||||||||||||
|
@@ -23,6 +24,7 @@ | |||||||||||||||||||||||||||||
from erpnext.setup.doctype.employee.employee import get_holiday_list_for_employee | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
import hrms | ||||||||||||||||||||||||||||||
from hrms.api import get_current_employee_info | ||||||||||||||||||||||||||||||
from hrms.hr.doctype.leave_block_list.leave_block_list import get_applicable_block_dates | ||||||||||||||||||||||||||||||
from hrms.hr.doctype.leave_ledger_entry.leave_ledger_entry import create_leave_ledger_entry | ||||||||||||||||||||||||||||||
from hrms.hr.utils import ( | ||||||||||||||||||||||||||||||
|
@@ -102,6 +104,7 @@ def on_submit(self): | |||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
self.validate_back_dated_application() | ||||||||||||||||||||||||||||||
self.update_attendance() | ||||||||||||||||||||||||||||||
self.validate_for_self_approval() | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
# notify leave applier about approval | ||||||||||||||||||||||||||||||
if frappe.db.get_single_value("HR Settings", "send_leave_notification"): | ||||||||||||||||||||||||||||||
|
@@ -791,6 +794,16 @@ def create_ledger_entry_for_intermediate_allocation_expiry(self, expiry_date, su | |||||||||||||||||||||||||||||
args.update(dict(from_date=start_date, to_date=self.to_date, leaves=leaves * -1)) | ||||||||||||||||||||||||||||||
create_leave_ledger_entry(self, args, submit) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
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().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) | ||||||||||||||||||||||||||||||
Comment on lines
+799
to
+805
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
def get_allocation_expiry_for_cf_leaves( | ||||||||||||||||||||||||||||||
employee: str, leave_type: str, to_date: datetime.date, from_date: datetime.date | ||||||||||||||||||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -967,6 +967,84 @@ def test_leave_approver_perms(self): | |
employee.leave_approver = "" | ||
employee.save() | ||
|
||
def test_self_leave_approval_allowed(self): | ||
frappe.db.set_single_value("HR Settings", "allow_self_leave_approval", 1) | ||
|
||
leave_approver = "[email protected]" | ||
make_employee(leave_approver, "_Test Company") | ||
|
||
employee = get_employee() | ||
if not employee.user_id: | ||
employee.user_id = "[email protected]" | ||
employee.leave_approver = leave_approver | ||
employee.save() | ||
|
||
from frappe.utils.user import add_role | ||
|
||
add_role(employee.user_id, "Leave Approver") | ||
|
||
make_allocation_record(employee.name) | ||
application = frappe.get_doc( | ||
doctype="Leave Application", | ||
employee=employee.name, | ||
leave_type="_Test Leave Type", | ||
from_date="2014-06-01", | ||
to_date="2014-06-02", | ||
posting_date="2014-05-30", | ||
description="_Test Reason", | ||
company="_Test Company", | ||
leave_approver=leave_approver, | ||
) | ||
application.insert() | ||
application.status = "Approved" | ||
|
||
frappe.set_user(employee.user_id) | ||
application.submit() | ||
|
||
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) | ||
|
||
leave_approver = "[email protected]" | ||
make_employee(leave_approver, "_Test Company") | ||
|
||
employee = get_employee() | ||
employee.leave_approver = leave_approver | ||
if not employee.user_id: | ||
employee.user_id = "[email protected]" | ||
employee.save() | ||
|
||
from frappe.utils.user import add_role | ||
|
||
add_role(employee.user_id, "Leave Approver") | ||
|
||
make_allocation_record(employee.name) | ||
application = application = frappe.get_doc( | ||
doctype="Leave Application", | ||
employee=employee.name, | ||
leave_type="_Test Leave Type", | ||
from_date="2014-06-03", | ||
to_date="2014-06-04", | ||
posting_date="2014-05-30", | ||
description="_Test Reason", | ||
company="_Test Company", | ||
leave_approver=leave_approver, | ||
) | ||
application.insert() | ||
application.status = "Approved" | ||
|
||
frappe.set_user(employee.user_id) | ||
self.assertRaises(frappe.ValidationError, application.submit) | ||
|
||
add_role(leave_approver, "Leave Approver") | ||
frappe.set_user(leave_approver) | ||
application.reload() | ||
application.submit() | ||
self.assertEqual(1, application.docstatus) | ||
|
||
@set_holiday_list("Salary Slip Test Holiday List", "_Test Company") | ||
def test_get_leave_details_for_dashboard(self): | ||
employee = get_employee() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fieldname says allow so keep it consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on this setting, Approval field should also become read-only - client-side change