Skip to content

Commit

Permalink
fix(Shift Assignment): calendar view date filter (backport #1477) (#1536
Browse files Browse the repository at this point in the history
)

* fix(Shift Assignment): calendar view date filter

* fix(Shift Assignment): account for unset end dates

* test: test for different date ranges

* chore(minor): add comment in test

---------

Co-authored-by: Rucha Mahabal <[email protected]>
(cherry picked from commit 6ddd029)

Co-authored-by: Akash  Tom <[email protected]>
  • Loading branch information
mergify[bot] and krantheman authored Mar 13, 2024
1 parent 6ce46a8 commit bf6c4bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 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 @@ -171,11 +171,14 @@ def get_shift_assignments(start: str, end: str, filters: str | list | None = Non
if not filters:
filters = []

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

or_filters = [["end_date", ">=", start], ["end_date", "is", "not set"]]

return frappe.get_list(
"Shift Assignment",
filters=filters,
or_filters=or_filters,
fields=[
"name",
"start_date",
Expand Down
25 changes: 20 additions & 5 deletions hrms/hr/doctype/shift_assignment/test_shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,32 @@ def test_multiple_shift_assignments_for_same_day(self):
def test_calendar(self):
employee1 = make_employee("[email protected]", company="_Test Company")
employee2 = make_employee("[email protected]", company="_Test Company")
employee3 = make_employee("[email protected]", company="_Test Company")

shift_type = setup_shift_type(shift_type="Shift 1", start_time="08:00:00", end_time="12:00:00")
date = getdate()
shift1 = make_shift_assignment(shift_type.name, employee1, date)
make_shift_assignment(shift_type.name, employee2, date)
shift1 = make_shift_assignment(shift_type.name, employee1, date) # 1 day
make_shift_assignment(shift_type.name, employee2, date) # excluded due to employee filter
make_shift_assignment(
shift_type.name, employee3, add_days(date, -3), add_days(date, -2)
) # excluded
shift2 = make_shift_assignment(shift_type.name, employee3, add_days(date, -1), date) # 2 days
shift3 = make_shift_assignment(
shift_type.name, employee3, add_days(date, 1), add_days(date, 2)
) # 2 days
shift4 = make_shift_assignment(
shift_type.name, employee3, add_days(date, 30), add_days(date, 30)
) # 1 day
make_shift_assignment(shift_type.name, employee3, add_days(date, 31)) # excluded

events = get_events(
start=date, end=date, filters=[["Shift Assignment", "employee", "=", employee1, False]]
start=date,
end=add_days(date, 30),
filters=[["Shift Assignment", "employee", "!=", employee2, False]],
)
self.assertEqual(len(events), 1)
self.assertEqual(events[0]["name"], shift1.name)
self.assertEqual(len(events), 6)
for shift in events:
self.assertIn(shift["name"], [shift1.name, shift2.name, shift3.name, shift4.name])

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

0 comments on commit bf6c4bd

Please sign in to comment.