From 5c73bafeaa34e325a8c555123cd4bd063ff1f568 Mon Sep 17 00:00:00 2001 From: Meatechsupport Date: Sun, 5 Jul 2015 11:26:55 +0400 Subject: [PATCH 1/5] 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", From e319598c51057c2e5036ddc4b719a28b21ac44f6 Mon Sep 17 00:00:00 2001 From: Meatechsupport Date: Mon, 27 Jul 2015 16:42:22 +0400 Subject: [PATCH 2/5] IndentationError alligned code --- .../leave_application/leave_application.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 5704775c23..2580bb1aaf 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -239,14 +239,14 @@ def get_total_leave_days(leave_app): 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) - } + 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() From 8b96fdac12f574bdcfd6280f2881d49e4e569beb Mon Sep 17 00:00:00 2001 From: Meatechsupport Date: Mon, 27 Jul 2015 16:55:54 +0400 Subject: [PATCH 3/5] Indentation Error realligned --- .../doctype/leave_application/leave_application.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 2580bb1aaf..68daa31dc5 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -240,13 +240,13 @@ def get_total_leave_days(leave_app): 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) - } + ret = { + 'total_leave_days' : flt(tot_days)-flt(holidays) + } + else: + ret = { + 'total_leave_days' : flt(tot_days) + } return ret @frappe.whitelist() From 145227e4ecb6ba8d69bf33e15dcc361bb91cd9f8 Mon Sep 17 00:00:00 2001 From: Meatechsupport Date: Tue, 28 Jul 2015 18:39:04 +0400 Subject: [PATCH 4/5] Edited the Test case --- .../test_leave_application.py | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index d9c0846908..97c6f2f655 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -19,7 +19,8 @@ _test_records = [ "from_date": "2013-05-01", "leave_type": "_Test Leave Type", "posting_date": "2013-01-02", - "to_date": "2013-05-05" + "to_date": "2013-05-05", + "get_holidays": "2013-05-03" }, { "company": "_Test Company", @@ -29,7 +30,8 @@ _test_records = [ "from_date": "2013-05-01", "leave_type": "_Test Leave Type", "posting_date": "2013-01-02", - "to_date": "2013-05-05" + "to_date": "2013-05-05", + "get_holidays": "2013-05-03" }, { "company": "_Test Company", @@ -39,7 +41,8 @@ _test_records = [ "from_date": "2013-01-15", "leave_type": "_Test Leave Type LWP", "posting_date": "2013-01-02", - "to_date": "2013-01-15" + "to_date": "2013-01-15", + "get_holidays": "2013-05-03" } ] @@ -250,27 +253,18 @@ class TestLeaveApplication(unittest.TestCase): 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 = frappe.copy_doc(_test_records[0]) 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 = frappe.copy_doc(_test_records[0]) 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 + self.assertEquals(application.ret, 5) \ No newline at end of file From e102332f088401cc632c2e47c994ed94c7f3efa5 Mon Sep 17 00:00:00 2001 From: Meatechsupport Date: Tue, 28 Jul 2015 19:03:30 +0400 Subject: [PATCH 5/5] removed testcase --- .../test_leave_application.py | 29 +++---------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index 97c6f2f655..9e2170855a 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -19,8 +19,7 @@ _test_records = [ "from_date": "2013-05-01", "leave_type": "_Test Leave Type", "posting_date": "2013-01-02", - "to_date": "2013-05-05", - "get_holidays": "2013-05-03" + "to_date": "2013-05-05" }, { "company": "_Test Company", @@ -30,8 +29,7 @@ _test_records = [ "from_date": "2013-05-01", "leave_type": "_Test Leave Type", "posting_date": "2013-01-02", - "to_date": "2013-05-05", - "get_holidays": "2013-05-03" + "to_date": "2013-05-05" }, { "company": "_Test Company", @@ -41,8 +39,7 @@ _test_records = [ "from_date": "2013-01-15", "leave_type": "_Test Leave Type LWP", "posting_date": "2013-01-02", - "to_date": "2013-01-15", - "get_holidays": "2013-05-03" + "to_date": "2013-01-15" } ] @@ -249,22 +246,4 @@ class TestLeaveApplication(unittest.TestCase): frappe.db.sql("""delete from `tabEmployee Leave Approver` where parent=%s""", "_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[0]) - 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[0]) - application.insert() - - self.assertEquals(application.tot_days, 5) - self.assertEquals(application.holidays, 1) - self.assertEquals(application.ret, 5) \ No newline at end of file + frappe.db.set_value("Employee", "_T-Employee-0001", "department", original_department) \ No newline at end of file