Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mark absence for default shift on non-overlapping dates if another shift assignment exists #2602

Merged
merged 7 commits into from
Jan 20, 2025
1 change: 1 addition & 0 deletions hrms/hr/doctype/shift_type/shift_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +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:
filters["start_date"] = ("=", from_date)
asmitahase marked this conversation as resolved.
Show resolved Hide resolved
default_shift_employees = self.get_employees_with_default_shift(filters)
assigned_employees = set(assigned_employees + default_shift_employees)

Expand Down
21 changes: 21 additions & 0 deletions hrms/hr/doctype/shift_type/test_shift_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"[email protected]", 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)
Expand Down
Loading