start adding locum availability

This commit is contained in:
Ross
2025-01-20 10:56:47 +00:00
parent 7ce4677921
commit 8459a4b3a9
5 changed files with 429 additions and 124 deletions
+27 -1
View File
@@ -87,7 +87,7 @@ class Worker(BaseModel):
site: str
# Grade are equivalent to roles, by keeping them integer defining model
# rules is easier.
grade: int
grade: int = 1
# We can either have a user generated ID
id: Optional[int | uuid.UUID | str] = None
fte: int = 100
@@ -98,11 +98,15 @@ class Worker(BaseModel):
not_available_to_work: list[NotAvailableToWork] = []
pref_not_to_work: list[PreferenceNotToWork] = []
work_requests: list[WorkRequests] = []
locum_availability: list[WorkRequests] = []
remote_site: str = "plymouth" # We set a default proc_site
previous_shifts: dict = {}
shift_balance_extra: dict = {}
bank_holiday_extra: int = 0
pair: int | str | None = None
locum: bool = False
shift_fte_overrides: dict[str, int] = {} # Need checks to ensure shifts exist
model_config = ConfigDict(
extra="allow",
@@ -284,6 +288,16 @@ class Worker(BaseModel):
else:
Rota.work_requests.add((self.id, week, day, request.shift))
for request in self.locum_availability:
days_from_start = (request.date - Rota.start_date).days
week = days_from_start // 7 + 1
day = Rota.days[(days_from_start % 7)]
if request.shift == "*":
for shift in Rota.get_shifts_for_worker_site(self.site):
Rota.locum_availability.add((self.id, week, day, shift.name))
else:
Rota.locum_availability.add((self.id, week, day, request.shift))
# Calculate the proportion of the rota that is being worked
self.proportion_rota_to_work = days_to_work / Rota.rota_days_length
self.days_to_work = days_to_work
@@ -291,6 +305,12 @@ class Worker(BaseModel):
# We have to adjust the full time equivalent for people who CCT / leave the rota early
self.fte_adj = self.fte * self.proportion_rota_to_work
self.fte_adj_shifts = {}
if self.shift_fte_overrides:
for shift, fte in self.shift_fte_overrides.items():
self.fte_adj_shifts[shift] = fte * self.proportion_rota_to_work
if self.fte_adj > 100:
# Shouldn't happen ? bug if it does
Rota.add_warning(
@@ -356,3 +376,9 @@ class Worker(BaseModel):
def get_shift_targets(self) -> dict:
return self.shift_target_number
def get_fte(self, shift: str | None=None) -> int:
if shift is not None:
if shift in self.fte_adj_shifts:
return self.fte_adj_shifts[shift]
return self.fte_adj