From 5c73bafeaa34e325a8c555123cd4bd063ff1f568 Mon Sep 17 00:00:00 2001 From: Meatechsupport Date: Sun, 5 Jul 2015 11:26:55 +0400 Subject: [PATCH] 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 --- .../leave_application/leave_application.py | 7 ++++- .../test_leave_application.py | 27 +++++++++++++++++++ erpnext/hr/doctype/leave_type/leave_type.json | 6 +++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index c75c2bd2f2..5704775c23 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -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() diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index 8cf0c80661..d9c0846908 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 @@ 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) \ 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 f644c696d1..4493af504c 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",