fix total being not zero when adding a new resolution
This commit is contained in:
@@ -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)"
|
||||
|
||||
Reference in New Issue
Block a user