mark holiday in the employee monthly attendance sheet (#10349)

This commit is contained in:
Manas Solanki 2017-08-10 11:20:58 +05:30 committed by Nabin Hait
parent e97f587411
commit a854ea00a5

View File

@ -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":"<b>H</b>"}
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""")