Merge pull request #5705 from KanchanChauhan/fixed-employee-holiday-attendance-report

Added Holiday List filter
This commit is contained in:
Rushabh Mehta 2016-07-12 11:11:43 +05:30 committed by GitHub
commit 4beba3aff9
2 changed files with 22 additions and 7 deletions

View File

@ -16,6 +16,12 @@ frappe.query_reports["Employee Holiday Attendance"] = {
"fieldtype": "Date",
"reqd": 1,
"default": frappe.datetime.year_end()
},
{
"fieldname":"holiday_list",
"label": __("Holiday List"),
"fieldtype": "Link",
"options": "Holiday List"
}
]
}

View File

@ -24,25 +24,34 @@ def get_columns():
_("Holiday") + ":Data:200"
]
def get_employees(filters):
holiday_filter = {"holiday_date": (">=", filters.from_date),
"holiday_date": ("<=", filters.to_date)}
if filters.holiday_list:
holiday_filter["parent"] = filters.holiday_list
holidays = frappe.get_all("Holiday", fields=["holiday_date", "description"],
filters=[["holiday_date", ">=",
filters.from_date],
["holiday_date", "<=", filters.to_date]])
filters=holiday_filter)
holiday_names = {}
holidays_list = []
for holiday in holidays:
holidays_list.append(holiday.holiday_date)
holiday_names[holiday.holiday_date] = holiday.description
if(holidays_list):
cond = " att_date in %(holidays_list)s"
if filters.holiday_list:
cond += """ and (employee in (select employee from tabEmployee where holiday_list = %(holidays)s))"""
employee_list = frappe.db.sql("""select
employee, employee_name, att_date, status
from tabAttendance
where
att_date in ({0})""".format(', '.join(["%s"] * len(holidays_list))),
holidays_list, as_list=True)
where %s"""% cond.format(', '.join(["%s"] * len(holidays_list))),
{'holidays_list':holidays_list,
'holidays':filters.holiday_list}, as_list=True)
for employee_data in employee_list:
employee_data.append(holiday_names[employee_data[2]])