diff --git a/hrms/hr/doctype/shift_type/shift_type.py b/hrms/hr/doctype/shift_type/shift_type.py index 328706c3f2..77174a03ab 100644 --- a/hrms/hr/doctype/shift_type/shift_type.py +++ b/hrms/hr/doctype/shift_type/shift_type.py @@ -242,7 +242,7 @@ def get_assigned_employees(self, from_date=None, consider_default_shift=False) - assigned_employees = frappe.get_all("Shift Assignment", filters=filters, pluck="employee") if consider_default_shift: - default_shift_employees = self.get_employees_with_default_shift(filters) + default_shift_employees = self.get_employees_with_default_shift(filters, from_date) assigned_employees = set(assigned_employees + default_shift_employees) # exclude inactive employees @@ -250,7 +250,8 @@ def get_assigned_employees(self, from_date=None, consider_default_shift=False) - return list(set(assigned_employees) - set(inactive_employees)) - def get_employees_with_default_shift(self, filters: dict) -> list: + def get_employees_with_default_shift(self, filters: dict, from_date) -> list: + filters["start_date"] = ("<=", from_date) default_shift_employees = frappe.get_all( "Employee", filters={"default_shift": self.name, "status": "Active"}, pluck="name" ) @@ -259,6 +260,7 @@ def get_employees_with_default_shift(self, filters: dict) -> list: return [] # exclude employees from default shift list if any other valid shift assignment exists + # that starts before the attendance processing date del filters["shift_type"] filters["employee"] = ("in", default_shift_employees) diff --git a/hrms/hr/doctype/shift_type/test_shift_type.py b/hrms/hr/doctype/shift_type/test_shift_type.py index 997856a52d..a5c3dd284a 100644 --- a/hrms/hr/doctype/shift_type/test_shift_type.py +++ b/hrms/hr/doctype/shift_type/test_shift_type.py @@ -612,6 +612,27 @@ def test_skip_auto_attendance_for_overlapping_shift(self): self.assertEqual(log_in.skip_auto_attendance, 1) self.assertEqual(log_out.skip_auto_attendance, 1) + def test_mark_attendance_for_default_shift_when_shift_assignment_is_not_overlapping(self): + shift_1 = setup_shift_type(shift_type="Deafult Shift", start_time="08:00:00", end_time="12:00:00") + shift_2 = setup_shift_type(shift_type="Not Default Shift", start_time="10:00:00", end_time="18:00:00") + employee = make_employee( + "test_employee_attendance@example.com", company="_Test Company", default_shift=shift_1.name + ) + shift_assigned_date = add_days(getdate(), +1) + make_shift_assignment(shift_2.name, employee, shift_assigned_date) + from hrms.hr.doctype.attendance.attendance import mark_attendance + + mark_attendance(employee, add_days(getdate(), -1), "Present", shift=shift_1.name) + shift_1.process_auto_attendance() + self.assertEqual( + frappe.db.get_value( + "Attendance", + {"employee": employee, "attendance_date": getdate(), "shift": shift_1.name}, + "status", + ), + "Absent", + ) + def setup_shift_type(**args): args = frappe._dict(args)