added holidy_block_list_allow
This commit is contained in:
parent
9cf478618f
commit
8c713e7f0c
@ -70,6 +70,11 @@ class DocType:
|
|||||||
webnotes.conn.set_default("employee", self.doc.name, self.doc.user_id)
|
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("employee_name", self.doc.employee_name, self.doc.user_id)
|
||||||
webnotes.conn.set_default("company", self.doc.company, 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):
|
def validate_date(self):
|
||||||
import datetime
|
import datetime
|
||||||
@ -134,4 +139,15 @@ test_records = [[{
|
|||||||
"status": "Active",
|
"status": "Active",
|
||||||
"company": "_Test Company",
|
"company": "_Test Company",
|
||||||
"user_id": "test@erpnext.com"
|
"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"
|
||||||
}]]
|
}]]
|
||||||
@ -31,4 +31,11 @@ test_records = [[{
|
|||||||
"parentfield": "holiday_block_list_dates",
|
"parentfield": "holiday_block_list_dates",
|
||||||
"block_date": "2013-01-02",
|
"block_date": "2013-01-02",
|
||||||
"reason": "First work day"
|
"reason": "First work day"
|
||||||
}]]
|
}, {
|
||||||
|
"doctype": "Holiday Block List Allow",
|
||||||
|
"parent": "_Test Holiday Block List",
|
||||||
|
"parenttype": "Holiday Block List",
|
||||||
|
"parentfield": "holiday_block_list_allowed",
|
||||||
|
"allow_user": "test1@erpnext.com",
|
||||||
|
}
|
||||||
|
]]
|
||||||
@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
"creation": "2013-02-04 15:31:29",
|
"creation": "2013-02-04 15:31:29",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-02-04 15:38:57",
|
"modified": "2013-02-06 14:39:09",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -53,6 +53,13 @@
|
|||||||
"options": "Fiscal Year",
|
"options": "Fiscal Year",
|
||||||
"reqd": 1
|
"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",
|
"doctype": "DocField",
|
||||||
"fieldname": "holiday_block_list_dates",
|
"fieldname": "holiday_block_list_dates",
|
||||||
@ -60,6 +67,20 @@
|
|||||||
"label": "Holiday Block List Dates",
|
"label": "Holiday Block List Dates",
|
||||||
"options": "Holiday Block List Date"
|
"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"
|
"doctype": "DocPerm"
|
||||||
}
|
}
|
||||||
|
|||||||
0
hr/doctype/holiday_block_list_allow/__init__.py
Normal file
0
hr/doctype/holiday_block_list_allow/__init__.py
Normal file
@ -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
|
||||||
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
@ -53,6 +53,8 @@ class DocType:
|
|||||||
if department:
|
if department:
|
||||||
block_list = webnotes.conn.get_value("Department", department, "holiday_block_list")
|
block_list = webnotes.conn.get_value("Department", department, "holiday_block_list")
|
||||||
if 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
|
for d in webnotes.conn.sql("""select block_date, reason from
|
||||||
`tabHoliday Block List Date` where parent=%s""", block_list, as_dict=1):
|
`tabHoliday Block List Date` where parent=%s""", block_list, as_dict=1):
|
||||||
block_date = getdate(d.block_date)
|
block_date = getdate(d.block_date)
|
||||||
@ -61,6 +63,10 @@ class DocType:
|
|||||||
+ ": " + formatdate(d.block_date) + _(" Reason: ") + d.reason)
|
+ ": " + formatdate(d.block_date) + _(" Reason: ") + d.reason)
|
||||||
raise LeaveDayBlockedError
|
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):
|
def get_holidays(self):
|
||||||
tot_hol = webnotes.conn.sql("""select count(*) from `tabHoliday` h1, `tabHoliday List` h2, `tabEmployee` e1
|
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
|
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):
|
def is_lwp(leave_type):
|
||||||
lwp = webnotes.conn.sql("select is_lwp from `tabLeave Type` where name = %s", 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
|
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"
|
|
||||||
}]]
|
|
||||||
@ -1,26 +1,50 @@
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
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):
|
class TestLeaveApplication(unittest.TestCase):
|
||||||
def setUp(self):
|
def test_block_list(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"])
|
|
||||||
import webnotes
|
import webnotes
|
||||||
webnotes.connect()
|
webnotes.conn.set_value("Employee", "_T-Employee-0001", "department",
|
||||||
unittest.main()
|
"_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()
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,7 @@ erpnext.toolbar.add_modules = function() {
|
|||||||
$('<li class="dropdown">\
|
$('<li class="dropdown">\
|
||||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#"\
|
<a class="dropdown-toggle" data-toggle="dropdown" href="#"\
|
||||||
title="'+wn._("Modules")+'"\
|
title="'+wn._("Modules")+'"\
|
||||||
onclick="return false;"><i class="icon-th"></i> <b class="caret"></b></a>\
|
onclick="return false;"><i class="icon-th"></i></a>\
|
||||||
<ul class="dropdown-menu modules">\
|
<ul class="dropdown-menu modules">\
|
||||||
</ul>\
|
</ul>\
|
||||||
</li>').prependTo('.navbar .nav:first');
|
</li>').prependTo('.navbar .nav:first');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user