From 5c73bafeaa34e325a8c555123cd4bd063ff1f568 Mon Sep 17 00:00:00 2001 From: Meatechsupport Date: Sun, 5 Jul 2015 11:26:55 +0400 Subject: [PATCH 1/6] 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/6] 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/6] 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/6] 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/6] 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 From b24d2efc4b99239f935b87a685e46cb5da2497c6 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 29 Jul 2015 16:15:08 +0530 Subject: [PATCH 6/6] [fix] Updated 'Include Holiday' in existing and default leave type records --- .../leave_application/leave_application.py | 2 +- erpnext/hr/doctype/leave_type/test_records.json | 6 ++++-- erpnext/patches.txt | 1 + .../setup/page/setup_wizard/install_fixtures.py | 15 ++++++++++----- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 226e95990f..7cbc59687a 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -245,7 +245,7 @@ def get_total_leave_days(leave_app): } else: ret = { - 'total_leave_days' : flt(tot_days) + 'total_leave_days' : flt(tot_days) } return ret diff --git a/erpnext/hr/doctype/leave_type/test_records.json b/erpnext/hr/doctype/leave_type/test_records.json index 8042e30f52..2ac46cf626 100644 --- a/erpnext/hr/doctype/leave_type/test_records.json +++ b/erpnext/hr/doctype/leave_type/test_records.json @@ -1,11 +1,13 @@ [ { "doctype": "Leave Type", - "leave_type_name": "_Test Leave Type" + "leave_type_name": "_Test Leave Type", + "include_holiday": 1 }, { "doctype": "Leave Type", "is_lwp": 1, - "leave_type_name": "_Test Leave Type LWP" + "leave_type_name": "_Test Leave Type LWP", + "include_holiday": 1 } ] \ No newline at end of file diff --git a/erpnext/patches.txt b/erpnext/patches.txt index ef08098c32..b029d55f5f 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -181,3 +181,4 @@ erpnext.patches.v5_1.rename_roles erpnext.patches.v5_1.default_bom execute:frappe.delete_doc("DocType", "Party Type") erpnext.patches.v5_4.fix_reserved_qty_and_sle_for_packed_items +execute:frappe.db.sql("update `tabLeave Type` set include_holiday=1") \ No newline at end of file diff --git a/erpnext/setup/page/setup_wizard/install_fixtures.py b/erpnext/setup/page/setup_wizard/install_fixtures.py index 6265e4a36c..dd3ec3a2e6 100644 --- a/erpnext/setup/page/setup_wizard/install_fixtures.py +++ b/erpnext/setup/page/setup_wizard/install_fixtures.py @@ -41,11 +41,16 @@ def install(country=None): {'doctype': 'Expense Claim Type', 'name': _('Travel'), 'expense_type': _('Travel')}, # leave type - {'doctype': 'Leave Type', 'leave_type_name': _('Casual Leave'), 'name': _('Casual Leave'), 'is_encash': 1, 'is_carry_forward': 1, 'max_days_allowed': '3', }, - {'doctype': 'Leave Type', 'leave_type_name': _('Compensatory Off'), 'name': _('Compensatory Off'), 'is_encash': 0, 'is_carry_forward': 0, }, - {'doctype': 'Leave Type', 'leave_type_name': _('Sick Leave'), 'name': _('Sick Leave'), 'is_encash': 0, 'is_carry_forward': 0, }, - {'doctype': 'Leave Type', 'leave_type_name': _('Privilege Leave'), 'name': _('Privilege Leave'), 'is_encash': 0, 'is_carry_forward': 0, }, - {'doctype': 'Leave Type', 'leave_type_name': _('Leave Without Pay'), 'name': _('Leave Without Pay'), 'is_encash': 0, 'is_carry_forward': 0, 'is_lwp':1}, + {'doctype': 'Leave Type', 'leave_type_name': _('Casual Leave'), 'name': _('Casual Leave'), + 'is_encash': 1, 'is_carry_forward': 1, 'max_days_allowed': '3', 'include_holiday': 1}, + {'doctype': 'Leave Type', 'leave_type_name': _('Compensatory Off'), 'name': _('Compensatory Off'), + 'is_encash': 0, 'is_carry_forward': 0, 'include_holiday': 1}, + {'doctype': 'Leave Type', 'leave_type_name': _('Sick Leave'), 'name': _('Sick Leave'), + 'is_encash': 0, 'is_carry_forward': 0, 'include_holiday': 1}, + {'doctype': 'Leave Type', 'leave_type_name': _('Privilege Leave'), 'name': _('Privilege Leave'), + 'is_encash': 0, 'is_carry_forward': 0, 'include_holiday': 1}, + {'doctype': 'Leave Type', 'leave_type_name': _('Leave Without Pay'), 'name': _('Leave Without Pay'), + 'is_encash': 0, 'is_carry_forward': 0, 'is_lwp':1, 'include_holiday': 1}, # Employment Type {'doctype': 'Employment Type', 'employee_type_name': _('Full-time')},