From a35dad7610d7ebb6d822956b91dedc40fe8948e6 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 10 May 2018 19:47:41 +0530 Subject: [PATCH 1/2] add get leave period method --- erpnext/hr/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py index 057f406e805..be8c948adde 100644 --- a/erpnext/hr/utils.py +++ b/erpnext/hr/utils.py @@ -49,3 +49,9 @@ def update_employee(employee, details, cancel=False): new_data = get_datetime(new_data) setattr(employee, item.fieldname, new_data) return employee + + +def get_leave_period(from_date, to_date, company): + return frappe.db.sql("""select name from `tabLeave Period` + where is_active=1 and company=%s + and to_date >= %s and from_date <= %s""", (company, to_date, from_date)) From c1acbdfb690f4ce7d410c2ae342fff205b07ac3c Mon Sep 17 00:00:00 2001 From: Saurabh Date: Sat, 12 May 2018 17:45:22 +0530 Subject: [PATCH 2/2] [fix] overlapping dates --- erpnext/hr/utils.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py index be8c948adde..686f79170c9 100644 --- a/erpnext/hr/utils.py +++ b/erpnext/hr/utils.py @@ -50,8 +50,19 @@ def update_employee(employee, details, cancel=False): setattr(employee, item.fieldname, new_data) return employee - def get_leave_period(from_date, to_date, company): - return frappe.db.sql("""select name from `tabLeave Period` - where is_active=1 and company=%s - and to_date >= %s and from_date <= %s""", (company, to_date, from_date)) + leave_period = frappe.db.sql(""" + select name, from_date, to_date + from `tabLeave Period` + where company=%(company)s and is_active=1 + 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 < %(from_date)s and to_date > %(to_date)s)) + """, { + "from_date": from_date, + "to_date": to_date, + "company": company + }, as_dict=1) + + if leave_period: + return leave_period