diff --git a/djangorota/rota/models.py b/djangorota/rota/models.py index e738f37..932ae65 100644 --- a/djangorota/rota/models.py +++ b/djangorota/rota/models.py @@ -153,13 +153,32 @@ class Worker(models.Model): except Exception: raise RuntimeError("Unable to import rota.workers.Worker; ensure project package is importable") - # Map fte: Django stores percentage (100) while pydantic Worker expects int + # Map fte: Django stores `fte` as a float (fractional e.g. 1.0 == 100%), + # while the pydantic Worker expects an integer percentage (100). + # Convert conservatively: + # - if stored value looks like a fraction (<= 10) treat it as fraction + # and multiply by 100 (e.g. 1.0 -> 100). + # - otherwise treat it as already a percentage and coerce to int. + raw_fte = getattr(self, "fte", None) + try: + if raw_fte is None: + fte_pct = 100 + else: + # numeric values + f = float(raw_fte) + if f <= 10: + fte_pct = int(round(f * 100)) + else: + fte_pct = int(round(f)) + except Exception: + fte_pct = 100 + pyd_kwargs = { "name": self.name, "site": self.site or "", "grade": self.grade or 1, "id": self.pk, - "fte": int(self.fte), + "fte": fte_pct, } # Merge any additional options stored on the Django model into the