Add guard against division by zero in target_shifts calculation with warning logging
This commit is contained in:
@@ -2007,6 +2007,19 @@ class RotaBuilder(object):
|
|||||||
for i in shift.sites
|
for i in shift.sites
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 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 = (
|
target_shifts = (
|
||||||
total_shifts
|
total_shifts
|
||||||
/ full_time_equivalent_joined
|
/ full_time_equivalent_joined
|
||||||
|
|||||||
Reference in New Issue
Block a user