Skip to content
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(HR): Leave Type configuration to allow over allocation #30940

Merged
merged 2 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion erpnext/hr/doctype/leave_allocation/leave_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,18 @@ def validate_total_leaves_allocated(self):
# Adding a day to include To Date in the difference
date_difference = date_diff(self.to_date, self.from_date) + 1
if date_difference < self.total_leaves_allocated:
frappe.throw(_("Total allocated leaves are more than days in the period"), OverAllocationError)
if frappe.db.get_value("Leave Type", self.leave_type, "allow_over_allocation"):
frappe.msgprint(
_("<b>Total Leaves Allocated</b> are more than the number of days in the allocation period"),
indicator="orange",
alert=True,
)
else:
frappe.throw(
_("<b>Total Leaves Allocated</b> are more than the number of days in the allocation period"),
exc=OverAllocationError,
title=_("Over Allocation"),
)

def create_leave_ledger_entry(self, submit=True):
if self.unused_leaves:
Expand Down
24 changes: 23 additions & 1 deletion erpnext/hr/doctype/leave_allocation/test_leave_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,44 @@ def test_invalid_period(self):
self.assertRaises(frappe.ValidationError, doc.save)

def test_validation_for_over_allocation(self):
leave_type = create_leave_type(leave_type_name="Test Over Allocation", is_carry_forward=1)
leave_type.save()

doc = frappe.get_doc(
{
"doctype": "Leave Allocation",
"__islocal": 1,
"employee": self.employee.name,
"employee_name": self.employee.employee_name,
"leave_type": "_Test Leave Type",
"leave_type": leave_type.name,
"from_date": getdate("2015-09-1"),
"to_date": getdate("2015-09-30"),
"new_leaves_allocated": 35,
"carry_forward": 1,
}
)

# allocated leave more than period
self.assertRaises(OverAllocationError, doc.save)

leave_type.allow_over_allocation = 1
leave_type.save()

# allows creating a leave allocation with more leave days than period days
doc = frappe.get_doc(
{
"doctype": "Leave Allocation",
"__islocal": 1,
"employee": self.employee.name,
"employee_name": self.employee.employee_name,
"leave_type": leave_type.name,
"from_date": getdate("2015-09-1"),
"to_date": getdate("2015-09-30"),
"new_leaves_allocated": 35,
"carry_forward": 1,
}
).insert()

def test_validation_for_over_allocation_post_submission(self):
allocation = frappe.get_doc(
{
Expand Down
12 changes: 11 additions & 1 deletion erpnext/hr/doctype/leave_type/leave_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"fraction_of_daily_salary_per_leave",
"is_optional_leave",
"allow_negative",
"allow_over_allocation",
"include_holiday",
"is_compensatory",
"carry_forward_section",
Expand Down Expand Up @@ -211,15 +212,23 @@
"fieldtype": "Float",
"label": "Fraction of Daily Salary per Leave",
"mandatory_depends_on": "eval:doc.is_ppl == 1"
},
{
"default": "0",
"description": "Allows allocating more leaves than the number of days in the allocation period.",
"fieldname": "allow_over_allocation",
"fieldtype": "Check",
"label": "Allow Over Allocation"
}
],
"icon": "fa fa-flag",
"idx": 1,
"links": [],
"modified": "2021-10-02 11:59:40.503359",
"modified": "2022-05-09 05:01:38.957545",
"modified_by": "Administrator",
"module": "HR",
"name": "Leave Type",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
Expand Down Expand Up @@ -251,5 +260,6 @@
],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}