From 1a00af00a31db21f32dec92fe986966fe91f1140 Mon Sep 17 00:00:00 2001 From: krantheman Date: Mon, 16 Sep 2024 17:07:20 +0530 Subject: [PATCH 1/2] fix: show shift for month full of leaves (cherry picked from commit 642fe9e2da6fae2bf7f803acf39d83c03d2711f2) --- .../monthly_attendance_sheet.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hrms/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py b/hrms/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py index 38cb93513f..9823a30ab9 100644 --- a/hrms/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py +++ b/hrms/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py @@ -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: @@ -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 From 004f9eda5074b799e4cf01be7b5b1fb12f0713dd Mon Sep 17 00:00:00 2001 From: krantheman Date: Mon, 16 Sep 2024 17:24:59 +0530 Subject: [PATCH 2/2] test: update test to check for shift of employees on leave (cherry picked from commit d8f0aa8b2cc5b6a90649201ac7d4a3d1719f346e) --- .../test_monthly_attendance_sheet.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hrms/hr/report/monthly_attendance_sheet/test_monthly_attendance_sheet.py b/hrms/hr/report/monthly_attendance_sheet/test_monthly_attendance_sheet.py index 25e5269ced..ad2066cd6f 100644 --- a/hrms/hr/report/monthly_attendance_sheet/test_monthly_attendance_sheet.py +++ b/hrms/hr/report/monthly_attendance_sheet/test_monthly_attendance_sheet.py @@ -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("employee@leave.com", 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, @@ -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)