From 8c713e7f0c6c8cfa49a0587f01bfcb99f07224d0 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 6 Feb 2013 16:10:48 +0530 Subject: [PATCH] added holidy_block_list_allow --- hr/doctype/employee/employee.py | 16 +++++ .../holiday_block_list/holiday_block_list.py | 9 ++- .../holiday_block_list/holiday_block_list.txt | 23 +++++- .../holiday_block_list_allow/__init__.py | 0 .../holiday_block_list_allow.py | 8 +++ .../holiday_block_list_allow.txt | 35 ++++++++++ .../leave_application/leave_application.py | 27 ++----- .../test_leave_application.py | 70 +++++++++++++------ public/js/toolbar.js | 2 +- 9 files changed, 144 insertions(+), 46 deletions(-) create mode 100644 hr/doctype/holiday_block_list_allow/__init__.py create mode 100644 hr/doctype/holiday_block_list_allow/holiday_block_list_allow.py create mode 100644 hr/doctype/holiday_block_list_allow/holiday_block_list_allow.txt diff --git a/hr/doctype/employee/employee.py b/hr/doctype/employee/employee.py index 4360c7e7ac..d08da1acba 100644 --- a/hr/doctype/employee/employee.py +++ b/hr/doctype/employee/employee.py @@ -70,6 +70,11 @@ class DocType: webnotes.conn.set_default("employee", self.doc.name, self.doc.user_id) webnotes.conn.set_default("employee_name", self.doc.employee_name, self.doc.user_id) webnotes.conn.set_default("company", self.doc.company, self.doc.user_id) + + # add employee role if missing + if not "Employee" in webnotes.conn.sql_list("""select role from tabUserRole + where parent=%s""", self.doc.user_id): + webnotes.get_obj("Profile", self.doc.user_id).add_role("Employee") def validate_date(self): import datetime @@ -134,4 +139,15 @@ test_records = [[{ "status": "Active", "company": "_Test Company", "user_id": "test@erpnext.com" +}], +[{ + "doctype":"Employee", + "employee_name": "_Test Employee 1", + "naming_series": "_T-Employee-", + "date_of_joining": "2010-01-01", + "date_of_birth": "1980-01-01", + "gender": "Male", + "status": "Active", + "company": "_Test Company", + "user_id": "test1@erpnext.com" }]] \ No newline at end of file diff --git a/hr/doctype/holiday_block_list/holiday_block_list.py b/hr/doctype/holiday_block_list/holiday_block_list.py index 4ebe49e188..619f373e37 100644 --- a/hr/doctype/holiday_block_list/holiday_block_list.py +++ b/hr/doctype/holiday_block_list/holiday_block_list.py @@ -31,4 +31,11 @@ test_records = [[{ "parentfield": "holiday_block_list_dates", "block_date": "2013-01-02", "reason": "First work day" - }]] \ No newline at end of file + }, { + "doctype": "Holiday Block List Allow", + "parent": "_Test Holiday Block List", + "parenttype": "Holiday Block List", + "parentfield": "holiday_block_list_allowed", + "allow_user": "test1@erpnext.com", + } + ]] \ No newline at end of file diff --git a/hr/doctype/holiday_block_list/holiday_block_list.txt b/hr/doctype/holiday_block_list/holiday_block_list.txt index 732e783b35..31b2f98ee1 100644 --- a/hr/doctype/holiday_block_list/holiday_block_list.txt +++ b/hr/doctype/holiday_block_list/holiday_block_list.txt @@ -2,7 +2,7 @@ { "creation": "2013-02-04 15:31:29", "docstatus": 0, - "modified": "2013-02-04 15:38:57", + "modified": "2013-02-06 14:39:09", "modified_by": "Administrator", "owner": "Administrator" }, @@ -53,6 +53,13 @@ "options": "Fiscal Year", "reqd": 1 }, + { + "description": "Stop users from making Leave Applications on following days.", + "doctype": "DocField", + "fieldname": "block_days", + "fieldtype": "Section Break", + "label": "Block Days" + }, { "doctype": "DocField", "fieldname": "holiday_block_list_dates", @@ -60,6 +67,20 @@ "label": "Holiday Block List Dates", "options": "Holiday Block List Date" }, + { + "description": "Allow the following users to make Leave Applications for block days.", + "doctype": "DocField", + "fieldname": "allow_list", + "fieldtype": "Section Break", + "label": "Allow Users" + }, + { + "doctype": "DocField", + "fieldname": "holiday_block_list_allowed", + "fieldtype": "Table", + "label": "Holiday Block List Allowed", + "options": "Holiday Block List Allow" + }, { "doctype": "DocPerm" } diff --git a/hr/doctype/holiday_block_list_allow/__init__.py b/hr/doctype/holiday_block_list_allow/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/hr/doctype/holiday_block_list_allow/holiday_block_list_allow.py b/hr/doctype/holiday_block_list_allow/holiday_block_list_allow.py new file mode 100644 index 0000000000..928aa9ff9f --- /dev/null +++ b/hr/doctype/holiday_block_list_allow/holiday_block_list_allow.py @@ -0,0 +1,8 @@ +# For license information, please see license.txt + +from __future__ import unicode_literals +import webnotes + +class DocType: + def __init__(self, d, dl): + self.doc, self.doclist = d, dl \ No newline at end of file diff --git a/hr/doctype/holiday_block_list_allow/holiday_block_list_allow.txt b/hr/doctype/holiday_block_list_allow/holiday_block_list_allow.txt new file mode 100644 index 0000000000..bdbd2a0186 --- /dev/null +++ b/hr/doctype/holiday_block_list_allow/holiday_block_list_allow.txt @@ -0,0 +1,35 @@ +[ + { + "creation": "2013-02-06 14:31:03", + "docstatus": 0, + "modified": "2013-02-06 14:31:03", + "modified_by": "Administrator", + "owner": "Administrator" + }, + { + "doctype": "DocType", + "istable": 1, + "module": "HR", + "name": "__common__" + }, + { + "doctype": "DocField", + "fieldname": "allow_user", + "fieldtype": "Link", + "label": "Allow User", + "name": "__common__", + "options": "Profile", + "parent": "Holiday Block List Allow", + "parentfield": "fields", + "parenttype": "DocType", + "permlevel": 0, + "width": "200px" + }, + { + "doctype": "DocType", + "name": "Holiday Block List Allow" + }, + { + "doctype": "DocField" + } +] \ No newline at end of file diff --git a/hr/doctype/leave_application/leave_application.py b/hr/doctype/leave_application/leave_application.py index 8c7124e92d..cab8f17b69 100755 --- a/hr/doctype/leave_application/leave_application.py +++ b/hr/doctype/leave_application/leave_application.py @@ -53,6 +53,8 @@ class DocType: if department: block_list = webnotes.conn.get_value("Department", department, "holiday_block_list") if block_list: + if self.is_user_in_allow_list(block_list): + return for d in webnotes.conn.sql("""select block_date, reason from `tabHoliday Block List Date` where parent=%s""", block_list, as_dict=1): block_date = getdate(d.block_date) @@ -61,6 +63,10 @@ class DocType: + ": " + formatdate(d.block_date) + _(" Reason: ") + d.reason) raise LeaveDayBlockedError + def is_user_in_allow_list(self, block_list): + return webnotes.session.user in webnotes.conn.sql_list("""select allow_user + from `tabHoliday Block List Allow` where parent=%s""", block_list) + def get_holidays(self): tot_hol = webnotes.conn.sql("""select count(*) from `tabHoliday` h1, `tabHoliday List` h2, `tabEmployee` e1 where e1.name = %s and h1.parent = h2.name and e1.holiday_list = h2.name @@ -147,23 +153,4 @@ def get_approver_list(): def is_lwp(leave_type): lwp = webnotes.conn.sql("select is_lwp from `tabLeave Type` where name = %s", leave_type) - return lwp and cint(lwp[0][0]) or 0 - -test_records = [ - [{ - "doctype": "Leave Allocation", - "leave_type": "_Test Leave Type", - "fiscal_year": "_Test Fiscal Year", - "employee":"_T-Employee-0001", - "new_leaves_allocated": 15, - "docstatus": 1 - }], - [{ - "doctype": "Leave Application", - "leave_type": "_Test Leave Type", - "from_date": "2013-05-01", - "to_date": "2013-05-05", - "posting_date": "2013-01-02", - "fiscal_year": "_Test Fiscal Year", - "employee": "_T-Employee-0001" - }]] \ No newline at end of file + return lwp and cint(lwp[0][0]) or 0 \ No newline at end of file diff --git a/hr/doctype/leave_application/test_leave_application.py b/hr/doctype/leave_application/test_leave_application.py index fac36857c4..e485289ffa 100644 --- a/hr/doctype/leave_application/test_leave_application.py +++ b/hr/doctype/leave_application/test_leave_application.py @@ -1,26 +1,50 @@ - import sys - import unittest +import sys +import unittest - from hr.doctype.leave_application.leave_application import test_records, LeaveDayBlockedError +from hr.doctype.leave_application.leave_application import LeaveDayBlockedError - class TestLeaveApplication(unittest.TestCase): - def setUp(self): - from webnotes.test_runner import make_test_records - make_test_records("Leave Application") - - def test_block_list(self): - import webnotes - webnotes.conn.set_value("Employee", "_T-Employee-0001", "department", - "_Test Department with Block List") - - application = webnotes.model_wrapper(test_records[1]) - application.doc.from_date = "2013-01-01" - application.doc.to_date = "2013-01-05" - self.assertRaises(LeaveDayBlockedError, application.insert) - - if __name__=="__main__": - sys.path.extend(["app", "lib"]) +class TestLeaveApplication(unittest.TestCase): + def test_block_list(self): import webnotes - webnotes.connect() - unittest.main() - \ No newline at end of file + webnotes.conn.set_value("Employee", "_T-Employee-0001", "department", + "_Test Department with Block List") + + application = webnotes.model_wrapper(test_records[1]) + application.doc.from_date = "2013-01-01" + application.doc.to_date = "2013-01-05" + self.assertRaises(LeaveDayBlockedError, application.insert) + + webnotes.session.user = "test1@erpnext.com" + webnotes.get_obj("Profile", "test1@erpnext.com").add_role("HR User") + self.assertTrue(application.insert()) + + +test_records = [ + [{ + "doctype": "Leave Allocation", + "leave_type": "_Test Leave Type", + "fiscal_year": "_Test Fiscal Year", + "employee":"_T-Employee-0001", + "new_leaves_allocated": 15, + "docstatus": 1 + }], + [{ + "doctype": "Leave Application", + "leave_type": "_Test Leave Type", + "from_date": "2013-05-01", + "to_date": "2013-05-05", + "posting_date": "2013-01-02", + "fiscal_year": "_Test Fiscal Year", + "employee": "_T-Employee-0001" + }]] + +if __name__=="__main__": + sys.path.extend(["app", "lib"]) + import webnotes + webnotes.connect() + + from webnotes.test_runner import make_test_records + make_test_records("Leave Application") + + unittest.main() + diff --git a/public/js/toolbar.js b/public/js/toolbar.js index fd7109ad89..8fd3d98330 100644 --- a/public/js/toolbar.js +++ b/public/js/toolbar.js @@ -52,7 +52,7 @@ erpnext.toolbar.add_modules = function() { $('').prependTo('.navbar .nav:first');