update from last round
This commit is contained in:
+21
-18
@@ -68,7 +68,7 @@ class Worker(BaseModel):
|
||||
# rules is easier.
|
||||
grade: int
|
||||
# We can either have a user generated ID
|
||||
id: Optional[int| uuid.UUID] = None
|
||||
id: Optional[int| uuid.UUID| str] = None
|
||||
fte: int = 100
|
||||
nwds: list[NonWorkingDays] = []
|
||||
start_date: datetime.date | None = None
|
||||
@@ -81,7 +81,7 @@ class Worker(BaseModel):
|
||||
previous_shifts: dict = {}
|
||||
shift_balance_extra: dict = {}
|
||||
bank_holiday_extra: int = 0
|
||||
pair: str | None = None
|
||||
pair: int | str | None = None
|
||||
|
||||
class Config:
|
||||
extra = Extra.allow
|
||||
@@ -161,6 +161,9 @@ class Worker(BaseModel):
|
||||
(self.id, week, day)
|
||||
] = f"END DATE: {self.calculated_end_date}"
|
||||
|
||||
if not self.not_available_to_work:
|
||||
Rota.add_warning("Worker/No unavailability", f"{self.name} [{self.id}] has no unavailabilities (leave)")
|
||||
|
||||
for item in self.oop:
|
||||
start_oop = item.start_date
|
||||
end_oop = item.end_date
|
||||
@@ -210,8 +213,8 @@ class Worker(BaseModel):
|
||||
days_to_end = (self.calculated_end_date - Rota.start_date).days
|
||||
|
||||
# loop throught dates converting to week / day combination
|
||||
for item in self.pref_not_to_work:
|
||||
days_from_start = (item.date - Rota.start_date).days
|
||||
for preference in self.pref_not_to_work:
|
||||
days_from_start = (preference.date - Rota.start_date).days
|
||||
# Ignore dates past the end of the rota (or end date)
|
||||
if days_from_start < days_to_end:
|
||||
week = days_from_start // 7 + 1
|
||||
@@ -222,32 +225,32 @@ class Worker(BaseModel):
|
||||
Rota.pref_not_to_work[(self.id, week, day)] = 1 / (
|
||||
len(self.pref_not_to_work) + 1
|
||||
)
|
||||
Rota.pref_not_to_work_reason[(self.id, week, day)] = item.reason
|
||||
Rota.pref_not_to_work_reason[(self.id, week, day)] = preference.reason
|
||||
|
||||
# print(not_available_to_work)
|
||||
# loop throught dates converting to week / day combination
|
||||
|
||||
unavailable_set = set()
|
||||
for item in self.not_available_to_work:
|
||||
days_from_start = (item.date - Rota.start_date).days
|
||||
for unavalability in self.not_available_to_work:
|
||||
days_from_start = (unavalability.date - Rota.start_date).days
|
||||
# Ignore dates past the end of the rota (or end date)
|
||||
if days_from_start < days_to_end:
|
||||
week = days_from_start // 7 + 1
|
||||
day = Rota.days[(days_from_start % 7)]
|
||||
Rota.unavailable_to_work.add((self.id, week, day))
|
||||
Rota.unavailable_to_work_reason[(self.id, week, day)] = item.reason
|
||||
Rota.unavailable_to_work_reason[(self.id, week, day)] = unavalability.reason
|
||||
unavailable_set.add((week, day))
|
||||
|
||||
|
||||
for item in self.work_requests:
|
||||
days_from_start = (item.date - Rota.start_date).days
|
||||
for request in self.work_requests:
|
||||
days_from_start = (request.date - Rota.start_date).days
|
||||
week = days_from_start // 7 + 1
|
||||
day = Rota.days[(days_from_start % 7)]
|
||||
if item.shift == "*":
|
||||
if request.shift == "*":
|
||||
for shift in Rota.get_shifts_for_worker_site(self.site):
|
||||
Rota.work_requests.add((self.id, week, day, shift.name))
|
||||
else:
|
||||
Rota.work_requests.add((self.id, week, day, item.shift))
|
||||
Rota.work_requests.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
|
||||
@@ -263,15 +266,15 @@ class Worker(BaseModel):
|
||||
|
||||
# TODO: this has already been validated, consider moving
|
||||
self.non_working_day_list = []
|
||||
for item in self.nwds:
|
||||
for non_working_day in self.nwds:
|
||||
start_date = Rota.start_date
|
||||
end_date = Rota.rota_end_date
|
||||
if item.start_date is not None:
|
||||
start_date = item.start_date
|
||||
if item.end_date is not None:
|
||||
end_date = item.end_date
|
||||
if non_working_day.start_date is not None:
|
||||
start_date = non_working_day.start_date
|
||||
if non_working_day.end_date is not None:
|
||||
end_date = non_working_day.end_date
|
||||
|
||||
self.non_working_day_list.append((item.day, start_date, end_date))
|
||||
self.non_working_day_list.append((non_working_day.day, start_date, end_date))
|
||||
|
||||
if days_to_work < 1:
|
||||
self.fte_adj = 0
|
||||
|
||||
Reference in New Issue
Block a user