Skip to content

Commit

Permalink
test: night shifts in calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed Jan 9, 2024
1 parent 70f6c48 commit ce61e1e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion hrms/hr/doctype/shift_assignment/shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,14 @@ def get_events(start, end, filters=None):
return get_shift_events(assignments)


def get_shift_assignments(start: str, end: str, filters: list) -> list[dict]:
def get_shift_assignments(start: str, end: str, filters: str | list | None = None) -> list[dict]:
import json

if isinstance(filters, str):
filters = json.loads(filters)
if not filters:
filters = []

filters.extend([["start_date", ">=", start], ["end_date", "<=", end], ["docstatus", "=", 1]])

return frappe.get_list(
Expand Down
13 changes: 12 additions & 1 deletion hrms/hr/doctype/shift_assignment/test_shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def test_multiple_shift_assignments_for_same_day(self):
date = getdate()
make_shift_assignment(shift_type.name, employee, date)

def test_shift_assignment_calendar(self):
def test_calendar(self):
employee1 = make_employee("[email protected]", company="_Test Company")
employee2 = make_employee("[email protected]", company="_Test Company")

Expand All @@ -242,6 +242,17 @@ def test_shift_assignment_calendar(self):
self.assertEqual(len(events), 1)
self.assertEqual(events[0]["name"], shift1.name)

def test_calendar_for_night_shift(self):
employee1 = make_employee("[email protected]", company="_Test Company")

shift_type = setup_shift_type(shift_type="Shift 1", start_time="08:00:00", end_time="02:00:00")
date = getdate()
shift = make_shift_assignment(shift_type.name, employee1, date, date)

events = get_events(start=date, end=date)
self.assertEqual(events[0]["start_date"], get_datetime(f"{date} 08:00:00"))
self.assertEqual(events[0]["end_date"], get_datetime(f"{add_days(date, 1)} 02:00:00"))

def test_consecutive_day_and_night_shifts(self):
# defaults
employee = make_employee("[email protected]", company="_Test Company")
Expand Down

0 comments on commit ce61e1e

Please sign in to comment.