From 8b5645d281bede7ece413405274a61b2ac634325 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 8 Feb 2013 15:29:13 +0530 Subject: [PATCH] leave application overlap validation: consider both open and approved leave applications --- hr/doctype/leave_application/leave_application.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hr/doctype/leave_application/leave_application.py b/hr/doctype/leave_application/leave_application.py index 9c6278d902..79d74c2757 100755 --- a/hr/doctype/leave_application/leave_application.py +++ b/hr/doctype/leave_application/leave_application.py @@ -123,15 +123,17 @@ class DocType: (self.doc.leave_type,), raise_exception=1) def validate_leave_overlap(self): - for d in webnotes.conn.sql("""select name, leave_type, posting_date, from_date, to_date + 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 - and docstatus = 1 + and docstatus < 2 + and status in ("Open", "Approved") 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 : %s" % (self.doc.employee, cstr(d['leave_type']), formatdate(d['from_date']), formatdate(d['to_date']), formatdate(d['posting_date']), d['name']), raise_exception = 1) + msgprint("Employee : %s has already applied for %s between %s and %s on %s. Please refer Leave Application : %s" % (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) def validate_max_days(self): max_days = webnotes.conn.sql("select max_days_allowed from `tabLeave Type` where name = '%s'" %(self.doc.leave_type))