Skip to content

Commit 1b09631

Browse files
authored
Merge pull request #4096 from frappe/mergify/bp/version-16-hotfix/pr-4068
fix(attendance): use valuewrapper for doctype in calendar view (backport #4068)
2 parents 6d89fe0 + 44ea5c7 commit 1b09631

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

hrms/hr/doctype/attendance/attendance.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
# License: GNU General Public License v3. See license.txt
33

44

5+
from datetime import date
6+
57
import frappe
68
from frappe import _
79
from frappe.model.document import Document
10+
from frappe.query_builder.terms import ValueWrapper
811
from frappe.utils import (
912
add_days,
1013
cint,
@@ -249,10 +252,11 @@ def publish_update(self):
249252

250253

251254
@frappe.whitelist()
252-
def get_events(start, end, filters=None):
255+
def get_events(start: date | str, end: date | str, filters: str | list | None = None) -> list[dict]:
253256
employee = frappe.db.get_value("Employee", {"user_id": frappe.session.user})
254257
if not employee:
255258
return []
259+
256260
if isinstance(filters, str):
257261
import json
258262

@@ -270,7 +274,7 @@ def add_attendance(filters):
270274
"Attendance",
271275
fields=[
272276
"name",
273-
"'Attendance' as doctype",
277+
ValueWrapper("Attendance").as_("doctype"),
274278
"attendance_date",
275279
"employee_name",
276280
"status",
@@ -279,7 +283,7 @@ def add_attendance(filters):
279283
filters=filters,
280284
)
281285
for record in attendance:
282-
record["title"] = f"{record.employee_name} : {record.status}"
286+
record["title"] = f"{record['employee_name']} : {record['status']}"
283287
return attendance
284288

285289

@@ -338,7 +342,7 @@ def mark_attendance(
338342

339343

340344
@frappe.whitelist()
341-
def mark_bulk_attendance(data):
345+
def mark_bulk_attendance(data: str | dict):
342346
import json
343347

344348
if isinstance(data, str):
@@ -348,11 +352,11 @@ def mark_bulk_attendance(data):
348352
frappe.throw(_("Please select a date."))
349353
return
350354

351-
for date in data.unmarked_days:
355+
for attendance_date in data.unmarked_days:
352356
doc_dict = {
353357
"doctype": "Attendance",
354358
"employee": data.employee,
355-
"attendance_date": get_datetime(date),
359+
"attendance_date": get_datetime(attendance_date),
356360
"status": data.status,
357361
"half_day_status": "Absent" if data.status == "Half Day" else None,
358362
"shift": data.shift,

hrms/hr/doctype/attendance/test_attendance.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from hrms.hr.doctype.attendance.attendance import (
2323
DuplicateAttendanceError,
2424
OverlappingShiftAttendanceError,
25+
get_events,
2526
get_unmarked_days,
2627
mark_attendance,
2728
)
@@ -268,5 +269,29 @@ def test_duplicate_attendance_when_created_from_checkins_and_tool(self):
268269
)
269270
self.assertEqual(len(attendances), 1)
270271

272+
def test_get_events_returns_attendance(self):
273+
employee = make_employee("calendar.user@example.com", company="_Test Company")
274+
275+
attendance_name = mark_attendance(employee, getdate(), status="Present")
276+
attendance = frappe.get_value("Attendance", attendance_name, "status")
277+
278+
self.assertEqual(attendance, "Present")
279+
280+
frappe.set_user("calendar.user@example.com")
281+
try:
282+
events = get_events(start=getdate(), end=getdate())
283+
finally:
284+
frappe.set_user("Administrator")
285+
286+
self.assertTrue(events)
287+
attendance_events = [e for e in events if e.get("doctype") == "Attendance"]
288+
self.assertTrue(attendance_events)
289+
self.assertEqual(attendance_events[0].get("status"), "Present")
290+
self.assertEqual(
291+
attendance_events[0].get("employee_name"),
292+
frappe.db.get_value("Employee", employee, "employee_name"),
293+
)
294+
self.assertEqual(attendance_events[0].get("attendance_date"), getdate())
295+
271296
def tearDown(self):
272297
frappe.db.rollback()

0 commit comments

Comments
 (0)