17
17
)
18
18
19
19
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
+ )
21
25
22
26
23
27
class DuplicateAttendanceError (frappe .ValidationError ):
@@ -227,25 +231,27 @@ def unlink_attendance_from_checkins(self):
227
231
228
232
@frappe .whitelist ()
229
233
def get_events (start , end , filters = None ):
234
+ from frappe .desk .reportview import get_filters_cond
235
+
230
236
events = []
231
237
232
238
employee = frappe .db .get_value ("Employee" , {"user_id" : frappe .session .user })
233
239
234
240
if not employee :
235
241
return events
236
242
237
- from frappe .desk .reportview import get_filters_cond
238
-
239
243
conditions = get_filters_cond ("Attendance" , filters , [])
240
244
add_attendance (events , start , end , conditions = conditions )
245
+ add_holidays (events , start , end , employee )
241
246
return events
242
247
243
248
244
249
def add_attendance (events , start , end , conditions = None ):
245
- query = """select name, attendance_date, status
250
+ query = """select name, attendance_date, status, employee_name
246
251
from `tabAttendance` where
247
252
attendance_date between %(from_date)s and %(to_date)s
248
253
and docstatus < 2"""
254
+
249
255
if conditions :
250
256
query += conditions
251
257
@@ -255,13 +261,32 @@ def add_attendance(events, start, end, conditions=None):
255
261
"doctype" : "Attendance" ,
256
262
"start" : d .attendance_date ,
257
263
"end" : d .attendance_date ,
258
- "title" : cstr (d .status ),
264
+ "title" : f"{ d .employee_name } : { cstr (d .status )} " ,
265
+ "status" : d .status ,
259
266
"docstatus" : d .docstatus ,
260
267
}
261
268
if e not in events :
262
269
events .append (e )
263
270
264
271
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
+
265
290
def mark_attendance (
266
291
employee ,
267
292
attendance_date ,
0 commit comments