From c3c59f1274f97e9d7a199fcd7f4cac4233ad01e4 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 20 Apr 2022 16:18:45 +0530 Subject: [PATCH] fix: shift fetching fails in Employee Checkin if shift assignment has an end date (backport #30701) (#30751) * fix: shift fetching fails in Employee Checkin if shift assignment has an end date Co-authored-by: Ejaaz Khan (cherry picked from commit 98cccf221e5d1d191b78bb1cb5a879e461e71b71) * test: shift fetching when assignment has an end date (cherry picked from commit 3cddc1e97e6831c508d309869e98cc53083f60ca) Co-authored-by: Rucha Mahabal --- .../employee_checkin/test_employee_checkin.py | 25 +++++++++++++++++++ .../shift_assignment/shift_assignment.py | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/erpnext/hr/doctype/employee_checkin/test_employee_checkin.py b/erpnext/hr/doctype/employee_checkin/test_employee_checkin.py index 81b44f8fea1..ced42bbc6ea 100644 --- a/erpnext/hr/doctype/employee_checkin/test_employee_checkin.py +++ b/erpnext/hr/doctype/employee_checkin/test_employee_checkin.py @@ -153,6 +153,31 @@ class TestEmployeeCheckin(FrappeTestCase): log = make_checkin(employee, timestamp) self.assertIsNone(log.shift) + def test_fetch_shift_for_assignment_with_end_date(self): + employee = make_employee("test_employee_checkin@example.com", company="_Test Company") + + # shift setup for 8-12 + shift1 = setup_shift_type() + # 12:30 - 16:30 + shift2 = setup_shift_type(shift_type="Shift 2", start_time="12:30:00", end_time="16:30:00") + + date = getdate() + make_shift_assignment(shift1.name, employee, date, add_days(date, 15)) + make_shift_assignment(shift2.name, employee, date, add_days(date, 15)) + + timestamp = datetime.combine(date, get_time("08:45:00")) + log = make_checkin(employee, timestamp) + self.assertEqual(log.shift, shift1.name) + + timestamp = datetime.combine(date, get_time("12:45:00")) + log = make_checkin(employee, timestamp) + self.assertEqual(log.shift, shift2.name) + + # log after end date + timestamp = datetime.combine(add_days(date, 16), get_time("12:45:00")) + log = make_checkin(employee, timestamp) + self.assertIsNone(log.shift) + def test_shift_start_and_end_timings(self): employee = make_employee("test_employee_checkin@example.com", company="_Test Company") diff --git a/erpnext/hr/doctype/shift_assignment/shift_assignment.py b/erpnext/hr/doctype/shift_assignment/shift_assignment.py index 0b21c00eac8..cbf798e690d 100644 --- a/erpnext/hr/doctype/shift_assignment/shift_assignment.py +++ b/erpnext/hr/doctype/shift_assignment/shift_assignment.py @@ -251,7 +251,7 @@ def get_shifts_for_date(employee: str, for_timestamp: datetime) -> List[Dict[str Criterion.any( [ assignment.end_date.isnull(), - (assignment.end_date.isnotnull() & (getdate(for_timestamp.date()) >= assignment.end_date)), + (assignment.end_date.isnotnull() & (getdate(for_timestamp.date()) <= assignment.end_date)), ] ) )