fix total being not zero when adding a new resolution

This commit is contained in:
2025-01-29 19:48:36 +01:00
parent 6d5694a153
commit a7ee650729

View File

@@ -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:
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)"