Skip to content

Commit

Permalink
Merge pull request #2201 from frappe/mergify/bp/version-14-hotfix/pr-…
Browse files Browse the repository at this point in the history
…2198

fix(Monthly Attendance Sheet): show shift for month full of leaves (backport #2198)
  • Loading branch information
krantheman authored Sep 17, 2024
2 parents 8e8380e + 004f9ed commit 3d12d30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def get_attendance_map(filters: Filters) -> dict:

for d in attendance_list:
if d.status == "On Leave":
leave_map.setdefault(d.employee, []).append(d.day_of_month)
leave_map.setdefault(d.employee, {}).setdefault(d.shift, []).append(d.day_of_month)
continue

if d.shift is None:
Expand All @@ -240,13 +240,14 @@ def get_attendance_map(filters: Filters) -> dict:

# leave is applicable for the entire day so all shifts should show the leave entry
for employee, leave_days in leave_map.items():
# no attendance records exist except leaves
if employee not in attendance_map:
attendance_map.setdefault(employee, {}).setdefault(None, {})

for day in leave_days:
for shift in attendance_map[employee].keys():
attendance_map[employee][shift][day] = "On Leave"
for assigned_shift, days in leave_days.items():
# no attendance records exist except leaves
if employee not in attendance_map:
attendance_map.setdefault(employee, {}).setdefault(assigned_shift, {})

for day in days:
for shift in attendance_map[employee].keys():
attendance_map[employee][shift][day] = "On Leave"

return attendance_map

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def test_monthly_attendance_sheet_report(self):
mark_attendance(self.employee, previous_month_first + relativedelta(days=1), "Present")
mark_attendance(self.employee, previous_month_first + relativedelta(days=2), "On Leave")

employee_on_leave_with_shift = make_employee("[email protected]", company=self.company)
mark_attendance(employee_on_leave_with_shift, previous_month_first, "On Leave", "Day Shift")

filters = frappe._dict(
{
"month": previous_month_first.month,
Expand All @@ -50,14 +53,14 @@ def test_monthly_attendance_sheet_report(self):
)
report = execute(filters=filters)

record = report[1][0]
datasets = report[3]["data"]["datasets"]
absent = datasets[0]["values"]
present = datasets[1]["values"]
leaves = datasets[2]["values"]

# ensure correct attendance is reflected on the report
self.assertEqual(self.employee, record.get("employee"))
self.assertEqual(self.employee, report[1][0].get("employee"))
self.assertEqual("Day Shift", report[1][1].get("shift"))
self.assertEqual(absent[0], 1)
self.assertEqual(present[1], 1)
self.assertEqual(leaves[2], 1)
Expand Down

0 comments on commit 3d12d30

Please sign in to comment.