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):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs) # to get the self.fields set
|
super().__init__(*args, **kwargs) # to get the self.fields set
|
||||||
|
|
||||||
resolution = kwargs.get("instance")
|
budget = 0.0
|
||||||
bills = Bill.objects.filter(resolution=resolution)
|
total = 0.0
|
||||||
total = 0
|
if (resolution := kwargs.get("instance")) is not None:
|
||||||
for elem in bills:
|
for elem in Bill.objects.filter(resolution=resolution):
|
||||||
total += elem.amount
|
total += elem.amount
|
||||||
|
|
||||||
|
budget = resolution.budget
|
||||||
|
|
||||||
self.fields["total"].disabled = True
|
self.fields["total"].disabled = True
|
||||||
self.fields["total"].initial = total
|
self.fields["total"].initial = total
|
||||||
self.fields["total"].label = "Gesamtsumme (EUR)"
|
self.fields["total"].label = "Gesamtsumme (EUR)"
|
||||||
self.fields["total"].required = False
|
self.fields["total"].required = False
|
||||||
|
|
||||||
budget = 0
|
|
||||||
if resolution:
|
|
||||||
budget = resolution.budget
|
|
||||||
|
|
||||||
self.fields["budget_remaining"].disabled = True
|
self.fields["budget_remaining"].disabled = True
|
||||||
self.fields["budget_remaining"].initial = budget - total
|
self.fields["budget_remaining"].initial = budget - total
|
||||||
self.fields["budget_remaining"].label = "Restbudget (EUR)"
|
self.fields["budget_remaining"].label = "Restbudget (EUR)"
|
||||||
|
|||||||
Reference in New Issue
Block a user