diff --git a/konova/forms.py b/konova/forms.py index cf868186..a2c1c0cc 100644 --- a/konova/forms.py +++ b/konova/forms.py @@ -481,8 +481,27 @@ class RecordModalForm(BaseModalForm): "confirm", msg ) + # Special case: Intervention + # Add direct checks for related compensations + if isinstance(self.instance, Intervention): + self._are_compensations_valid() return super_val and checker.valid + def _are_compensations_valid(self): + """ Runs a special case for intervention-compensations validity + + Returns: + + """ + comps = self.instance.compensations.all() + for comp in comps: + checker = comp.quality_check() + for msg in checker.messages: + self.add_error( + "confirm", + f"{comp.identifier}: {msg}" + ) + def save(self): with transaction.atomic(): if self.cleaned_data["confirm"]: