Skip to content

Commit

Permalink
fix(Monthly Attendance Sheet): handle case when there are only leave …
Browse files Browse the repository at this point in the history
…records (backport #565) (#567)

Co-authored-by: Rucha Mahabal <ruchamahabal2@gmail.com>
  • Loading branch information
mergify[bot] and ruchamahabal committed Jun 2, 2023
1 parent 4b45df2 commit 8e81bc7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
Expand Up @@ -201,14 +201,17 @@ def get_data(filters: Filters, attendance_map: Dict) -> List[Dict]:
def get_attendance_map(filters: Filters) -> Dict:
"""Returns a dictionary of employee wise attendance map as per shifts for all the days of the month like
{
'employee1': {
'Morning Shift': {1: 'Present', 2: 'Absent', ...}
'Evening Shift': {1: 'Absent', 2: 'Present', ...}
},
'employee2': {
'Afternoon Shift': {1: 'Present', 2: 'Absent', ...}
'Night Shift': {1: 'Absent', 2: 'Absent', ...}
}
'employee1': {
'Morning Shift': {1: 'Present', 2: 'Absent', ...}
'Evening Shift': {1: 'Absent', 2: 'Present', ...}
},
'employee2': {
'Afternoon Shift': {1: 'Present', 2: 'Absent', ...}
'Night Shift': {1: 'Absent', 2: 'Absent', ...}
},
'employee3': {
None: {1: 'On Leave'}
}
}
"""
attendance_list = get_attendance_records(filters)
Expand All @@ -220,11 +223,15 @@ def get_attendance_map(filters: Filters) -> Dict:
leave_map.setdefault(d.employee, []).append(d.day_of_month)
continue

attendance_map.setdefault(d.employee, frappe._dict()).setdefault(d.shift, frappe._dict())
attendance_map.setdefault(d.employee, {}).setdefault(d.shift, {})
attendance_map[d.employee][d.shift][d.day_of_month] = d.status

# 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"
Expand Down
Expand Up @@ -130,6 +130,30 @@ def test_single_shift_with_leaves_in_detailed_view(self):
self.assertEqual(day_shift_row[2], "P") # present on the 2nd day
self.assertEqual(day_shift_row[3], "L") # leave on the 3rd day

@set_holiday_list("Salary Slip Test Holiday List", "_Test Company")
def test_single_leave_record(self):
previous_month_first = get_first_day_for_prev_month()
company = frappe.db.get_value("Employee", self.employee, "company")

# attendance without shift
mark_attendance(self.employee, previous_month_first, "On Leave")

filters = frappe._dict(
{
"month": previous_month_first.month,
"year": previous_month_first.year,
"company": company,
}
)
report = execute(filters=filters)

# single row with leave record
self.assertEqual(len(report[1]), 1)
row = report[1][0]

self.assertIsNone(row["shift"])
self.assertEqual(row[1], "L")

@set_holiday_list("Salary Slip Test Holiday List", "_Test Company")
def test_summarized_view(self):
previous_month_first = get_first_day_for_prev_month()
Expand Down

0 comments on commit 8e81bc7

Please sign in to comment.