diff --git a/fet2020/finance/forms.py b/fet2020/finance/forms.py index 3ace9c9d..ad58dc06 100644 --- a/fet2020/finance/forms.py +++ b/fet2020/finance/forms.py @@ -439,21 +439,19 @@ class ResolutionAdminForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # to get the self.fields set - resolution = kwargs.get("instance") - bills = Bill.objects.filter(resolution=resolution) - total = 0 - for elem in bills: - total += elem.amount + budget = 0.0 + total = 0.0 + if (resolution := kwargs.get("instance")) is not None: + for elem in Bill.objects.filter(resolution=resolution): + total += elem.amount + + budget = resolution.budget self.fields["total"].disabled = True self.fields["total"].initial = total self.fields["total"].label = "Gesamtsumme (EUR)" self.fields["total"].required = False - budget = 0 - if resolution: - budget = resolution.budget - self.fields["budget_remaining"].disabled = True self.fields["budget_remaining"].initial = budget - total self.fields["budget_remaining"].label = "Restbudget (EUR)"