added company in leave application and global holiday block list

This commit is contained in:
Rushabh Mehta 2013-02-07 09:09:14 +05:30
parent 958f08e77d
commit 981577050c
7 changed files with 88 additions and 22 deletions

View File

@ -23,7 +23,8 @@ class DocType:
test_records = [[{
"doctype":"Holiday Block List",
"holiday_block_list_name": "_Test Holiday Block List",
"year": "_Test Fiscal Year"
"year": "_Test Fiscal Year",
"company": "_Test Company"
}, {
"doctype": "Holiday Block List Date",
"parent": "_Test Holiday Block List",

View File

@ -2,7 +2,7 @@
{
"creation": "2013-02-04 15:31:29",
"docstatus": 0,
"modified": "2013-02-06 14:39:09",
"modified": "2013-02-07 08:47:25",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -53,6 +53,21 @@
"options": "Fiscal Year",
"reqd": 1
},
{
"doctype": "DocField",
"fieldname": "company",
"fieldtype": "Link",
"label": "Company",
"options": "Company",
"reqd": 1
},
{
"description": "If not checked, the list will have to be added to each Department where it has to be applied.",
"doctype": "DocField",
"fieldname": "applies_to_all_departments",
"fieldtype": "Check",
"label": "Applies to all Departments"
},
{
"description": "Stop users from making Leave Applications on following days.",
"doctype": "DocField",

View File

@ -46,22 +46,39 @@ class DocType:
raise_exception=True)
def validate_block_days(self):
from_date = getdate(self.doc.from_date)
to_date = getdate(self.doc.to_date)
for block_list in self.get_applicable_block_lists():
self.check_block_dates(block_list)
def get_applicable_block_lists(self):
block_lists = []
def add_block_list(block_list):
if block_list:
if not self.is_user_in_allow_list(block_list):
block_lists.append(block_list)
# per department
department = webnotes.conn.get_value("Employee", self.doc.employee, "department")
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)
if block_date > from_date and block_date < to_date:
webnotes.msgprint(_("You cannot apply for a leave on the following date because it is blocked")
+ ": " + formatdate(d.block_date) + _(" Reason: ") + d.reason)
raise LeaveDayBlockedError
add_block_list(block_list)
# global
for block_list in webnotes.conn.sql_list("""select name from `tabHoliday Block List`
where ifnull(applies_to_all_departments,0)=1 and company=%s""", self.doc.company):
add_block_list(block_list)
return block_lists
def check_block_dates(self, block_list):
from_date = getdate(self.doc.from_date)
to_date = getdate(self.doc.to_date)
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)
if block_date > from_date and block_date < to_date:
webnotes.msgprint(_("You cannot apply for a leave on the following date because it is blocked")
+ ": " + 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

View File

@ -1,8 +1,8 @@
[
{
"creation": "2013-01-10 16:34:14",
"creation": "2013-02-02 14:40:08",
"docstatus": 0,
"modified": "2013-02-01 10:34:14",
"modified": "2013-02-07 08:54:22",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -180,6 +180,15 @@
"reqd": 1,
"search_index": 0
},
{
"doctype": "DocField",
"fieldname": "company",
"fieldtype": "Link",
"label": "Company",
"options": "Company",
"permlevel": 0,
"reqd": 1
},
{
"doctype": "DocField",
"fieldname": "letter_head",
@ -241,4 +250,4 @@
"role": "Leave Approver",
"submit": 0
}
]
]

View File

@ -4,20 +4,33 @@ import unittest
from hr.doctype.leave_application.leave_application import LeaveDayBlockedError
class TestLeaveApplication(unittest.TestCase):
def get_application(self):
application = webnotes.model_wrapper(test_records[1])
application.doc.from_date = "2013-01-01"
application.doc.to_date = "2013-01-05"
return 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"
application = self.get_application()
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())
def test_global_block_list(self):
application = self.get_application()
webnotes.conn.set_value("Holiday Block List", "_Test Holiday Block List",
"applies_to_all_departments", 1)
webnotes.conn.set_value("Employee", "_T-Employee-0001", "department",
"_Test Department")
webnotes.session.user = "test@erpnext.com"
self.assertRaises(LeaveDayBlockedError, application.insert)
test_records = [
[{
@ -35,7 +48,8 @@ test_records = [
"to_date": "2013-05-05",
"posting_date": "2013-01-02",
"fiscal_year": "_Test Fiscal Year",
"employee": "_T-Employee-0001"
"employee": "_T-Employee-0001",
"company": "_Test Company"
}]]
if __name__=="__main__":

View File

@ -0,0 +1,9 @@
def execute():
import webnotes
webnotes.conn.sql("""update `tabLeave Application`, `tabEmployee` set
`tabLeave Application`.company = `tabEmployee`.company where
`tabLeave Application`.employee = `tabEmployee`.name""")
company = webnotes.conn.get_default("company")
webnotes.conn.sql("""update `tabLeave Application`
set company = %s where ifnull(company,'')=''""", company)

View File

@ -166,4 +166,5 @@ patch_list = [
"patches.february_2013.remove_sales_order_pending_items",
"patches.february_2013.account_negative_balance",
"patches.february_2013.remove_account_utils_folder",
"patches.february_2013.update_company_in_leave_application"
]