Skip to content

Commit

Permalink
feat: show holidays and colour code in attendance calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
vinyselopal committed Mar 28, 2024
1 parent b48cdcc commit 4e39521
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
37 changes: 31 additions & 6 deletions hrms/hr/doctype/attendance/attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
)

from hrms.hr.doctype.shift_assignment.shift_assignment import has_overlapping_timings
from hrms.hr.utils import get_holiday_dates_for_employee, validate_active_employee
from hrms.hr.utils import (
get_holiday_dates_for_employee,
get_holidays_for_employee,
validate_active_employee,
)


class DuplicateAttendanceError(frappe.ValidationError):
Expand Down Expand Up @@ -238,14 +242,16 @@ def get_events(start, end, filters=None):

conditions = get_filters_cond("Attendance", filters, [])
add_attendance(events, start, end, conditions=conditions)
add_holidays(events, start, end, employee)
return events


def add_attendance(events, start, end, conditions=None):
query = """select name, attendance_date, status
from `tabAttendance` where
attendance_date between %(from_date)s and %(to_date)s
and docstatus < 2"""
query = """select name, attendance_date, status, employee_name
from `tabAttendance` where
attendance_date between %(from_date)s and %(to_date)s
and docstatus < 2"""

if conditions:
query += conditions

Expand All @@ -255,13 +261,32 @@ def add_attendance(events, start, end, conditions=None):
"doctype": "Attendance",
"start": d.attendance_date,
"end": d.attendance_date,
"title": cstr(d.status),
"title": f"{d.employee_name}-{cstr(d.status)}",
"status": d.status,
"docstatus": d.docstatus,
}
if e not in events:
events.append(e)


def add_holidays(events, start, end, employee=None):
holidays = get_holidays_for_employee(employee, start, end)
if not holidays:
return

for holiday in holidays:
events.append(
{
"doctype": "Holiday",
"start": holiday.holiday_date,
"end": holiday.holiday_date,
"title": _("Holiday") + ": " + cstr(holiday.description),
"name": holiday.name,
"allDay": 1,
}
)


def mark_attendance(
employee,
attendance_date,
Expand Down
35 changes: 27 additions & 8 deletions hrms/hr/doctype/attendance/attendance_calendar.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.views.calendar["Attendance"] = {
options: {
header: {
left: 'prev,next today',
center: 'title',
right: 'month'
}
},
get_events_method: "hrms.hr.doctype.attendance.attendance.get_events"
field_map: {
start: "start",
end: "end",
id: "name",
title: "title",
allDay: "allDay",
color: "color",
},
get_css_class: function (data) {
console.log("data", data);
if (data.doctype === "Holiday") return "default";
if (data.doctype === "Attendance") {
if (data.status === "Absent" || data.status === "On Leave") {
return "danger";
}
if (data.status === "Half Day") return "warning";
return "success";
}
},
options: {
header: {
left: "prev,next today",
center: "title",
right: "month",
},
},
get_events_method: "hrms.hr.doctype.attendance.attendance.get_events",
};

0 comments on commit 4e39521

Please sign in to comment.