completed Time Log / Time Log Batch

This commit is contained in:
Rushabh Mehta
2013-03-01 18:24:52 +05:30
parent b21eb9ac09
commit fee642d547
27 changed files with 402 additions and 42 deletions

View File

@@ -22,6 +22,7 @@ from webnotes.utils import cint, cstr, date_diff, flt, formatdate, getdate, get_
from webnotes import msgprint
class LeaveDayBlockedError(Exception): pass
class OverlapError(Exception): pass
from webnotes.model.controller import DocListController
class DocType(DocListController):
@@ -129,17 +130,22 @@ class DocType(DocListController):
(self.doc.leave_type,), raise_exception=1)
def validate_leave_overlap(self):
if not self.doc.name:
self.doc.name = "New Leave Application"
for d in webnotes.conn.sql("""select name, leave_type, posting_date,
from_date, to_date
from `tabLeave Application`
where
(from_date <= %(to_date)s and to_date >= %(from_date)s)
and employee = %(employee)s
employee = %(employee)s
and docstatus < 2
and status in ("Open", "Approved")
and (from_date between %(from_date)s and %(to_date)s
or to_date between %(from_date)s and %(to_date)s
or %(from_date)s between from_date and to_date)
and name != %(name)s""", self.doc.fields, as_dict = 1):
msgprint("Employee : %s has already applied for %s between %s and %s on %s. Please refer Leave Application : <a href=\"#Form/Leave Application/%s\">%s</a>" % (self.doc.employee, cstr(d['leave_type']), formatdate(d['from_date']), formatdate(d['to_date']), formatdate(d['posting_date']), d['name'], d['name']), raise_exception = 1)
msgprint("Employee : %s has already applied for %s between %s and %s on %s. Please refer Leave Application : <a href=\"#Form/Leave Application/%s\">%s</a>" % (self.doc.employee, cstr(d['leave_type']), formatdate(d['from_date']), formatdate(d['to_date']), formatdate(d['posting_date']), d['name'], d['name']), raise_exception = OverlapError)
def validate_max_days(self):
max_days = webnotes.conn.sql("select max_days_allowed from `tabLeave Type` where name = '%s'" %(self.doc.leave_type))

View File

@@ -1,7 +1,7 @@
import webnotes
import unittest
from hr.doctype.leave_application.leave_application import LeaveDayBlockedError
from hr.doctype.leave_application.leave_application import LeaveDayBlockedError, OverlapError
class TestLeaveApplication(unittest.TestCase):
def get_application(self, doclist):
@@ -23,13 +23,22 @@ class TestLeaveApplication(unittest.TestCase):
from webnotes.profile import add_role
add_role("test1@example.com", "HR User")
# clear other applications
webnotes.conn.sql("delete from `tabLeave Application`")
application = self.get_application(test_records[1])
self.assertTrue(application.insert())
def test_overlap(self):
application = self.get_application(test_records[1])
self.assertRaises(OverlapError, application.insert)
def test_global_block_list(self):
application = self.get_application(test_records[3])
application.doc.leave_approver = "test@example.com"
webnotes.conn.set_value("Leave Block List", "_Test Leave Block List",
"applies_to_all_departments", 1)
webnotes.conn.set_value("Employee", "_T-Employee-0002", "department",