Skip to content

Commit 9365b55

Browse files
authored
Merge pull request #1637 from frappe/mergify/bp/version-14-hotfix/pr-1595
feat: show holidays and colour code in attendance calendar (backport #1595)
2 parents e252e89 + ddc1183 commit 9365b55

File tree

3 files changed

+64
-11
lines changed

3 files changed

+64
-11
lines changed

hrms/hr/doctype/attendance/attendance.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
"idx": 1,
208208
"is_submittable": 1,
209209
"links": [],
210-
"modified": "2023-06-15 20:09:21.730465",
210+
"modified": "2024-04-05 20:55:02.905452",
211211
"modified_by": "Administrator",
212212
"module": "HR",
213213
"name": "Attendance",
@@ -254,6 +254,16 @@
254254
"share": 1,
255255
"submit": 1,
256256
"write": 1
257+
},
258+
{
259+
"email": 1,
260+
"export": 1,
261+
"print": 1,
262+
"read": 1,
263+
"report": 1,
264+
"role": "Employee",
265+
"select": 1,
266+
"share": 1
257267
}
258268
],
259269
"search_fields": "employee,employee_name,attendance_date,status",

hrms/hr/doctype/attendance/attendance.py

+30-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
)
1818

1919
from hrms.hr.doctype.shift_assignment.shift_assignment import has_overlapping_timings
20-
from hrms.hr.utils import get_holiday_dates_for_employee, validate_active_employee
20+
from hrms.hr.utils import (
21+
get_holiday_dates_for_employee,
22+
get_holidays_for_employee,
23+
validate_active_employee,
24+
)
2125

2226

2327
class DuplicateAttendanceError(frappe.ValidationError):
@@ -227,25 +231,27 @@ def unlink_attendance_from_checkins(self):
227231

228232
@frappe.whitelist()
229233
def get_events(start, end, filters=None):
234+
from frappe.desk.reportview import get_filters_cond
235+
230236
events = []
231237

232238
employee = frappe.db.get_value("Employee", {"user_id": frappe.session.user})
233239

234240
if not employee:
235241
return events
236242

237-
from frappe.desk.reportview import get_filters_cond
238-
239243
conditions = get_filters_cond("Attendance", filters, [])
240244
add_attendance(events, start, end, conditions=conditions)
245+
add_holidays(events, start, end, employee)
241246
return events
242247

243248

244249
def add_attendance(events, start, end, conditions=None):
245-
query = """select name, attendance_date, status
250+
query = """select name, attendance_date, status, employee_name
246251
from `tabAttendance` where
247252
attendance_date between %(from_date)s and %(to_date)s
248253
and docstatus < 2"""
254+
249255
if conditions:
250256
query += conditions
251257

@@ -255,13 +261,32 @@ def add_attendance(events, start, end, conditions=None):
255261
"doctype": "Attendance",
256262
"start": d.attendance_date,
257263
"end": d.attendance_date,
258-
"title": cstr(d.status),
264+
"title": f"{d.employee_name}: {cstr(d.status)}",
265+
"status": d.status,
259266
"docstatus": d.docstatus,
260267
}
261268
if e not in events:
262269
events.append(e)
263270

264271

272+
def add_holidays(events, start, end, employee=None):
273+
holidays = get_holidays_for_employee(employee, start, end)
274+
if not holidays:
275+
return
276+
277+
for holiday in holidays:
278+
events.append(
279+
{
280+
"doctype": "Holiday",
281+
"start": holiday.holiday_date,
282+
"end": holiday.holiday_date,
283+
"title": _("Holiday") + ": " + cstr(holiday.description),
284+
"name": holiday.name,
285+
"allDay": 1,
286+
}
287+
)
288+
289+
265290
def mark_attendance(
266291
employee,
267292
attendance_date,
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
22
// For license information, please see license.txt
33
frappe.views.calendar["Attendance"] = {
4+
field_map: {
5+
start: "start",
6+
end: "end",
7+
id: "name",
8+
title: "title",
9+
allDay: "allDay",
10+
color: "color",
11+
},
12+
get_css_class: function (data) {
13+
if (data.doctype === "Holiday") return "default";
14+
else if (data.doctype === "Attendance") {
15+
if (data.status === "Absent" || data.status === "On Leave") {
16+
return "danger";
17+
}
18+
if (data.status === "Half Day") return "warning";
19+
return "success";
20+
}
21+
},
422
options: {
523
header: {
6-
left: 'prev,next today',
7-
center: 'title',
8-
right: 'month'
9-
}
24+
left: "prev,next today",
25+
center: "title",
26+
right: "month",
27+
},
1028
},
11-
get_events_method: "hrms.hr.doctype.attendance.attendance.get_events"
29+
get_events_method: "hrms.hr.doctype.attendance.attendance.get_events",
1230
};

0 commit comments

Comments
 (0)