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
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index c75c2bd..5704775 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -238,10 +238,15 @@
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()
diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py
index 8cf0c80..d9c0846 100644
--- a/erpnext/hr/doctype/leave_application/test_leave_application.py
+++ b/erpnext/hr/doctype/leave_application/test_leave_application.py
@@ -247,3 +247,30 @@
"_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)
\ No newline at end of file
diff --git a/erpnext/hr/doctype/leave_type/leave_type.json b/erpnext/hr/doctype/leave_type/leave_type.json
index f644c69..4493af5 100644
--- a/erpnext/hr/doctype/leave_type/leave_type.json
+++ b/erpnext/hr/doctype/leave_type/leave_type.json
@@ -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",