|
6 | 6 |
|
7 | 7 | from erpnext.setup.doctype.employee.test_employee import make_employee |
8 | 8 |
|
| 9 | +from hrms.hr.doctype.attendance.attendance import mark_attendance |
9 | 10 | from hrms.hr.doctype.shift_type.test_shift_type import setup_shift_type |
10 | 11 | from hrms.hr.report.shift_attendance.shift_attendance import execute |
11 | 12 | from hrms.tests.test_utils import create_company |
@@ -224,6 +225,48 @@ def test_user_permission_on_attendance_records(self): |
224 | 225 | assistant.reports_to = "" |
225 | 226 | assistant.save() |
226 | 227 |
|
| 228 | + def test_get_attendance_records_without_checkins(self): |
| 229 | + emp = make_employee("test_shift_report@example.com", company="_Test Company") |
| 230 | + |
| 231 | + mark_attendance(emp, date(2023, 1, 1), "Present", "Shift 1", late_entry=1, early_exit=0) |
| 232 | + mark_attendance(emp, date(2023, 1, 2), "Half Day", "Shift 2", late_entry=0, early_exit=1) |
| 233 | + mark_attendance(emp, date(2023, 1, 2), "Absent", "Shift 1", late_entry=1, early_exit=1) |
| 234 | + |
| 235 | + filters = frappe._dict( |
| 236 | + { |
| 237 | + "company": "_Test Company", |
| 238 | + "from_date": date(2023, 1, 1), |
| 239 | + "to_date": date(2023, 1, 3), |
| 240 | + "include_attendance_without_checkins": 1, |
| 241 | + } |
| 242 | + ) |
| 243 | + |
| 244 | + report = execute(filters) |
| 245 | + table_data = report[1] |
| 246 | + self.assertEqual(len(table_data), 9) |
| 247 | + |
| 248 | + chart_data = get_chart_data(report) |
| 249 | + frappe.db.commit() |
| 250 | + self.assertEqual(chart_data.present_records, 5) |
| 251 | + self.assertEqual(chart_data.half_day_records, 2) |
| 252 | + self.assertEqual(chart_data.absent_records, 2) |
| 253 | + self.assertEqual(chart_data.late_entries, 4) |
| 254 | + self.assertEqual(chart_data.early_exits, 6) |
| 255 | + |
| 256 | + # filter by shift |
| 257 | + filters["shift"] = "Shift 1" |
| 258 | + report = execute(filters) |
| 259 | + table_data = report[1] |
| 260 | + self.assertEqual(len(table_data), 5) |
| 261 | + |
| 262 | + chart_data = get_chart_data(report) |
| 263 | + |
| 264 | + self.assertEqual(chart_data.present_records, 4) |
| 265 | + self.assertEqual(chart_data.half_day_records, 0) |
| 266 | + self.assertEqual(chart_data.absent_records, 1) |
| 267 | + self.assertEqual(chart_data.late_entries, 3) |
| 268 | + self.assertEqual(chart_data.early_exits, 2) |
| 269 | + |
227 | 270 |
|
228 | 271 | def get_chart_data(report): |
229 | 272 | return frappe._dict( |
|
0 commit comments