diff --git a/AKModel/models.py b/AKModel/models.py index 8831be92f918210de9c757d2a08d670da137c4f1..5fc04ffba0945a3b010f74a259c6743dea549dd6 100644 --- a/AKModel/models.py +++ b/AKModel/models.py @@ -404,18 +404,29 @@ class Event(models.Model): slots_updated = 0 for scheduled_slot in schedule["scheduled_aks"]: scheduled_slot["timeslot_ids"] = list(map(int, scheduled_slot["timeslot_ids"])) + slot = AKSlot.objects.get(id=int(scheduled_slot["ak_id"])) + start_timeslot = timeslot_dict[min(scheduled_slot["timeslot_ids"])].avail end_timeslot = timeslot_dict[max(scheduled_slot["timeslot_ids"])].avail + solver_duration = (end_timeslot.end - start_timeslot.start).total_seconds() / 3600.0 + + if solver_duration + 1e-4 < slot.duration: + raise ValueError( + _( + "Duration of AK {ak_name} assigned by solver ({solver_duration} hours) " + "is less than the duration required by the slot ({slot_duration} hours)" + ).format( + ak_name=slot.ak.name, + solver_duration=solver_duration, + slot_duration=slot.duration, + ) + ) - slot = AKSlot.objects.get(id=int(scheduled_slot["ak_id"])) slot.room = Room.objects.get(id=int(scheduled_slot["room_id"])) slot.start = start_timeslot.start - - solver_duration = (end_timeslot.end - start_timeslot.start).total_seconds() / 3600.0 - assert solver_duration + 1e-4 >= slot.duration - slot.save() slots_updated += 1 + return slots_updated class AKOwner(models.Model):