diff --git a/rota_generator/shifts.py b/rota_generator/shifts.py index 1633576..4d5c44c 100644 --- a/rota_generator/shifts.py +++ b/rota_generator/shifts.py @@ -2007,11 +2007,24 @@ class RotaBuilder(object): for i in shift.sites ) - target_shifts = ( - total_shifts - / full_time_equivalent_joined - * worker.get_fte(shift=shift.name) - ) + # Guard against division by zero: if no full-time + # equivalent is available for the shift's sites the + # denominator may be zero (for example when all site + # FTEs are 0). In that case emit a warning and set the + # target to 0 rather than raising an exception. + if not full_time_equivalent_joined: + # avoid ZeroDivisionError + self.add_warning( + "Zero FTE for sites", + f"full_time_equivalent sum is zero for shift {shift.name}; setting target_shifts=0 for worker {worker.name}", + ) + target_shifts = 0 + else: + target_shifts = ( + total_shifts + / full_time_equivalent_joined + * worker.get_fte(shift=shift.name) + ) if self.use_previous_shifts: if shift.name in worker.previous_shifts: