mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-30 18:34:48 +00:00
added company in leave application and global holiday block list
This commit is contained in:
@@ -23,7 +23,8 @@ class DocType:
|
|||||||
test_records = [[{
|
test_records = [[{
|
||||||
"doctype":"Holiday Block List",
|
"doctype":"Holiday Block List",
|
||||||
"holiday_block_list_name": "_Test 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",
|
"doctype": "Holiday Block List Date",
|
||||||
"parent": "_Test Holiday Block List",
|
"parent": "_Test Holiday Block List",
|
||||||
|
|||||||
@@ -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-06 14:39:09",
|
"modified": "2013-02-07 08:47:25",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@@ -53,6 +53,21 @@
|
|||||||
"options": "Fiscal Year",
|
"options": "Fiscal Year",
|
||||||
"reqd": 1
|
"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.",
|
"description": "Stop users from making Leave Applications on following days.",
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
|
|||||||
@@ -46,22 +46,39 @@ class DocType:
|
|||||||
raise_exception=True)
|
raise_exception=True)
|
||||||
|
|
||||||
def validate_block_days(self):
|
def validate_block_days(self):
|
||||||
from_date = getdate(self.doc.from_date)
|
for block_list in self.get_applicable_block_lists():
|
||||||
to_date = getdate(self.doc.to_date)
|
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")
|
department = webnotes.conn.get_value("Employee", self.doc.employee, "department")
|
||||||
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:
|
add_block_list(block_list)
|
||||||
if self.is_user_in_allow_list(block_list):
|
|
||||||
return
|
# global
|
||||||
for d in webnotes.conn.sql("""select block_date, reason from
|
for block_list in webnotes.conn.sql_list("""select name from `tabHoliday Block List`
|
||||||
`tabHoliday Block List Date` where parent=%s""", block_list, as_dict=1):
|
where ifnull(applies_to_all_departments,0)=1 and company=%s""", self.doc.company):
|
||||||
block_date = getdate(d.block_date)
|
add_block_list(block_list)
|
||||||
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")
|
return block_lists
|
||||||
+ ": " + formatdate(d.block_date) + _(" Reason: ") + d.reason)
|
|
||||||
raise LeaveDayBlockedError
|
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):
|
def is_user_in_allow_list(self, block_list):
|
||||||
return webnotes.session.user in webnotes.conn.sql_list("""select allow_user
|
return webnotes.session.user in webnotes.conn.sql_list("""select allow_user
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-01-10 16:34:14",
|
"creation": "2013-02-02 14:40:08",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-02-01 10:34:14",
|
"modified": "2013-02-07 08:54:22",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@@ -180,6 +180,15 @@
|
|||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"search_index": 0
|
"search_index": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"doctype": "DocField",
|
||||||
|
"fieldname": "company",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Company",
|
||||||
|
"options": "Company",
|
||||||
|
"permlevel": 0,
|
||||||
|
"reqd": 1
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "letter_head",
|
"fieldname": "letter_head",
|
||||||
|
|||||||
@@ -4,20 +4,33 @@ import unittest
|
|||||||
from hr.doctype.leave_application.leave_application import LeaveDayBlockedError
|
from hr.doctype.leave_application.leave_application import LeaveDayBlockedError
|
||||||
|
|
||||||
class TestLeaveApplication(unittest.TestCase):
|
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):
|
def test_block_list(self):
|
||||||
import webnotes
|
import webnotes
|
||||||
webnotes.conn.set_value("Employee", "_T-Employee-0001", "department",
|
webnotes.conn.set_value("Employee", "_T-Employee-0001", "department",
|
||||||
"_Test Department with Block List")
|
"_Test Department with Block List")
|
||||||
|
|
||||||
application = webnotes.model_wrapper(test_records[1])
|
application = self.get_application()
|
||||||
application.doc.from_date = "2013-01-01"
|
|
||||||
application.doc.to_date = "2013-01-05"
|
|
||||||
self.assertRaises(LeaveDayBlockedError, application.insert)
|
self.assertRaises(LeaveDayBlockedError, application.insert)
|
||||||
|
|
||||||
webnotes.session.user = "test1@erpnext.com"
|
webnotes.session.user = "test1@erpnext.com"
|
||||||
webnotes.get_obj("Profile", "test1@erpnext.com").add_role("HR User")
|
webnotes.get_obj("Profile", "test1@erpnext.com").add_role("HR User")
|
||||||
self.assertTrue(application.insert())
|
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 = [
|
test_records = [
|
||||||
[{
|
[{
|
||||||
@@ -35,7 +48,8 @@ test_records = [
|
|||||||
"to_date": "2013-05-05",
|
"to_date": "2013-05-05",
|
||||||
"posting_date": "2013-01-02",
|
"posting_date": "2013-01-02",
|
||||||
"fiscal_year": "_Test Fiscal Year",
|
"fiscal_year": "_Test Fiscal Year",
|
||||||
"employee": "_T-Employee-0001"
|
"employee": "_T-Employee-0001",
|
||||||
|
"company": "_Test Company"
|
||||||
}]]
|
}]]
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -166,4 +166,5 @@ patch_list = [
|
|||||||
"patches.february_2013.remove_sales_order_pending_items",
|
"patches.february_2013.remove_sales_order_pending_items",
|
||||||
"patches.february_2013.account_negative_balance",
|
"patches.february_2013.account_negative_balance",
|
||||||
"patches.february_2013.remove_account_utils_folder",
|
"patches.february_2013.remove_account_utils_folder",
|
||||||
|
"patches.february_2013.update_company_in_leave_application"
|
||||||
]
|
]
|
||||||
Reference in New Issue
Block a user