From a854ea00a5102d05760943af53bbb0dd66678a9b Mon Sep 17 00:00:00 2001 From: Manas Solanki Date: Thu, 10 Aug 2017 11:20:58 +0530 Subject: [PATCH] mark holiday in the employee monthly attendance sheet (#10349) --- .../monthly_attendance_sheet.py | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py index 05d3df565a..bb200a997e 100644 --- a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py +++ b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py @@ -15,6 +15,12 @@ def execute(filters=None): att_map = get_attendance_list(conditions, filters) emp_map = get_employee_details() + holiday_list = [emp_map[d]["holiday_list"] for d in emp_map if emp_map[d]["holiday_list"]] + default_holiday_list = frappe.db.get_value("Company", filters.get("company"), "default_holiday_list") + holiday_list.append(default_holiday_list) + holiday_list = list(set(holiday_list)) + holiday_map = get_holiday(holiday_list, filters["month"]) + data = [] for emp in sorted(att_map): emp_det = emp_map.get(emp) @@ -27,7 +33,11 @@ def execute(filters=None): total_p = total_a = total_l = 0.0 for day in range(filters["total_days_in_month"]): status = att_map.get(emp).get(day + 1, "None") - status_map = {"Present": "P", "Absent": "A", "Half Day": "H", "On Leave": "L", "None": ""} + status_map = {"Present": "P", "Absent": "A", "Half Day": "HD", "On Leave": "L", "None": "", "Holiday":"H"} + if status == "None" and holiday_map: + emp_holiday_list = emp_det.holiday_list if emp_det.holiday_list else default_holiday_list + if (day+1) in holiday_map[emp_holiday_list]: + status = "Holiday" row.append(status_map[status]) if status == "Present": @@ -88,13 +98,21 @@ def get_conditions(filters): def get_employee_details(): emp_map = frappe._dict() - for d in frappe.db.sql("""select name, employee_name, designation, - department, branch, company - from tabEmployee""", as_dict=1): + for d in frappe.db.sql("""select name, employee_name, designation, department, branch, company, + holiday_list from tabEmployee""", as_dict=1): emp_map.setdefault(d.name, d) return emp_map +def get_holiday(holiday_list, month): + holiday_map = frappe._dict() + for d in holiday_list: + if d: + holiday_map.setdefault(d, frappe.db.sql_list('''select day(holiday_date) from `tabHoliday` + where parent=%s and month(holiday_date)=%s''', (d, month))) + + return holiday_map + @frappe.whitelist() def get_attendance_years(): year_list = frappe.db.sql_list("""select distinct YEAR(attendance_date) from tabAttendance ORDER BY YEAR(attendance_date) DESC""")