Modifying the number of leave days calculation part.
we don't need to exclude the Holiday list (that comes in between) from the total number of leaves applied. Add option in the leave type added a field in the leave type to include and exclude the holidays from the tolal leave applied days Added the field Added a field Include Holiday to leave Type doctype changed the lable changed the lable from "Include Holiday" to "Include holidays within leaves as leaves" Rearranged the function moved holidays = leave_app.get_holidays() under if Corrected 'total_leave_days' : flt(tot_days)-flt(holidays) Adding test case added the test case Added test case Added test case to test_leave_application.py adding default value added default value and corrected the syntax. IndentationError removed extra tabs after
This commit is contained in:
parent
77f04e293a
commit
5c73bafeaa
@ -238,10 +238,15 @@ def get_total_leave_days(leave_app):
|
||||
ret = {'total_leave_days' : 0.5}
|
||||
if not leave_app.half_day:
|
||||
tot_days = date_diff(leave_app.to_date, leave_app.from_date) + 1
|
||||
if frappe.db.get_value("Leave Type", self.leave_type, "include_holiday"):
|
||||
holidays = leave_app.get_holidays()
|
||||
ret = {
|
||||
'total_leave_days' : flt(tot_days)-flt(holidays)
|
||||
}
|
||||
}
|
||||
else:
|
||||
ret = {
|
||||
'total_leave_days' : flt(tot_days)
|
||||
}
|
||||
return ret
|
||||
|
||||
@frappe.whitelist()
|
||||
|
@ -247,3 +247,30 @@ class TestLeaveApplication(unittest.TestCase):
|
||||
"_T-Employee-0001")
|
||||
|
||||
frappe.db.set_value("Employee", "_T-Employee-0001", "department", original_department)
|
||||
|
||||
def test_exclude_holiday_in_leave(self):
|
||||
frappe.db.set_value("Leave Type", self.leave_type, "include_holiday", 0)
|
||||
application = frappe.copy_doc(_test_records[2])
|
||||
application.from_date = "2015-07-01"
|
||||
application.to_date = "2015-07-05"
|
||||
application.get_holidays = "2015-07-03"
|
||||
application.insert()
|
||||
|
||||
self.assertEquals(application.tot_days, 5)
|
||||
self.assertEquals(application.holidays, 1)
|
||||
self.assertEquals(application.ret, 4)
|
||||
|
||||
def test_include_holiday_in_leave(self):
|
||||
frappe.db.set_value("Leave Type", self.leave_type, "include_holiday", 1)
|
||||
application = frappe.copy_doc(_test_records[2])
|
||||
application.from_date = "2015-07-01"
|
||||
application.to_date = "2015-07-05"
|
||||
application.get_holidays = "2015-07-03"
|
||||
application.insert()
|
||||
|
||||
self.assertEquals(application.tot_days, 5)
|
||||
self.assertEquals(application.holidays, 1)
|
||||
self.assertEquals(application.ret, 5)
|
||||
|
||||
def tearDown(self):
|
||||
frappe.db.set_value("Leave Type", self.leave_type, "include_holiday", 0)
|
@ -59,6 +59,12 @@
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow Negative Balance",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "include_holiday",
|
||||
"fieldtype": "Check",
|
||||
"label": "Include holidays within leaves as leaves",
|
||||
"permlevel": 0
|
||||
}
|
||||
],
|
||||
"icon": "icon-flag",
|
||||
|
Loading…
x
Reference in New Issue
Block a user