Skip to content

Commit

Permalink
feat(HR): Leave Type configuration to allow over allocation (backport f…
Browse files Browse the repository at this point in the history
…rappe#30940) (frappe#30944)

Co-authored-by: Rucha Mahabal <ruchamahabal2@gmail.com>
  • Loading branch information
mergify[bot] and ruchamahabal committed May 10, 2022
1 parent 7ce5c93 commit 64440fc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
13 changes: 12 additions & 1 deletion erpnext/hr/doctype/leave_allocation/leave_allocation.py
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
Expand Up @@ -68,22 +68,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
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
}

0 comments on commit 64440fc

Please sign in to comment.