From 51135a152220eed69f600aee796c5a8c9b90702e Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 25 Mar 2016 11:13:11 +0530 Subject: [PATCH] [fix] fix get holidays in leave application --- .../leave_application/leave_application.py | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 5bf7e9ddfa..a28da1993f 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -335,16 +335,25 @@ def get_leave_allocation_records(date, employee=None): def get_holidays(employee, from_date, to_date): - tot_hol = frappe.db.sql("""select count(*) from `tabHoliday` h1, `tabHoliday List` h2, `tabEmployee` e1 - where e1.name = %s and h1.parent = h2.name and e1.holiday_list = h2.name - and h1.holiday_date between %s and %s""", (employee, from_date, to_date))[0][0] - - if not tot_hol: - tot_hol = frappe.db.sql("""select count(distinct holiday_date) from `tabHoliday` h1, `tabHoliday List` h2 + '''get holidays between two dates for the given employee''' + def get_from_holiday_list(from_date, to_date, holiday_list): + return frappe.db.sql("""select count(distinct holiday_date) from `tabHoliday` h1, `tabHoliday List` h2 where h1.parent = h2.name and h1.holiday_date between %s and %s - and h2.is_default = 1""", (from_date, to_date))[0][0] + and h2.name = %s""", (from_date, to_date, default_holiday_list))[0][0] - return tot_hol + holiday_list, company = frappe.db.get_value('Employee', employee, ['holiday_list', 'company']) + if holiday_list: + holidays = get_from_holiday_list(from_date, to_date, holiday_list) + + else: + default_holiday_list = frappe.db.get_value('Company', company, 'default_holiday_list') + + if default_holiday_list: + holidays = get_from_holiday_list(from_date, to_date, default_holiday_list) + else: + frappe.throw(_('Please set a default holiday list for Employee {0} or Company {0}').format(employee, company)) + + return holidays def is_lwp(leave_type): lwp = frappe.db.sql("select is_lwp from `tabLeave Type` where name = %s", leave_type)