allow shift registrations end to start
continuous-integration/drone/push Build is passing Details

This commit is contained in:
xAndy 2025-05-17 20:00:16 +02:00
parent c5bb532749
commit d7d26c56b0
2 changed files with 24 additions and 3 deletions

View File

@ -145,10 +145,10 @@ class Helper(models.Model):
)
|
# Case 2: End time falls between new shift's start and end
Q(shift_end__gt=shift.start_at, shift_end__lte=new_shift_end)
Q(shift_end__gt=shift.start_at, shift_end__lt=new_shift_end)
|
# Case 3: Completely encompasses the new shift
Q(shift__start_at__lte=shift.start_at, shift_end__gte=new_shift_end)
Q(shift__start_at__lt=shift.start_at, shift_end__gt=new_shift_end)
)
.first()
)

View File

@ -43,11 +43,32 @@ class ShiftOverlapTests(TestCase):
)
self.assertIsNone(self.helper.has_overlapping_shift(shift_before))
def test_back_to_back_shifts(self):
"""Test that a shift starting exactly when another ends is allowed"""
shift_after = Shift.objects.create(
room=self.room,
start_at=self.base_shift.start_at + self.base_shift.duration,
duration=timedelta(hours=1),
required_helpers=1,
)
self.assertIsNone(self.helper.has_overlapping_shift(shift_after))
# Also test the reverse case - registering for a shift that ends exactly when another begins
self.base_registration.delete()
ShiftRegistration.objects.create(
shift=shift_after,
helper=self.helper,
state=ShiftRegistration.RegState.REGISTERED,
)
self.assertIsNone(self.helper.has_overlapping_shift(self.base_shift))
def test_no_overlap_after(self):
"""Test a shift that starts after the base shift ends"""
shift_after = Shift.objects.create(
room=self.room,
start_at=self.base_shift.start_at + timedelta(hours=4),
start_at=self.base_shift.start_at
+ self.base_shift.duration
+ timedelta(hours=1),
duration=timedelta(hours=1),
required_helpers=1,
)