limit shown finance information to the current year
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
|
from django.utils import timezone
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
|
||||||
from gaehsnitz.models import Donation, Payment
|
from gaehsnitz.models import Donation, Payment
|
||||||
@@ -37,12 +38,16 @@ class FinanceView(GaehsnitzTemplateView):
|
|||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
total_donations = Donation.objects.all().aggregate(sum=Sum("amount"))["sum"]
|
year = timezone.now().year
|
||||||
total_payments = Payment.objects.all().aggregate(sum=Sum("amount"))["sum"]
|
donations = Donation.objects.filter(date__year=year)
|
||||||
|
payments = Payment.objects.filter(date__year=year)
|
||||||
|
|
||||||
|
total_donations = donations.aggregate(sum=Sum("amount"))["sum"] or 0
|
||||||
|
total_payments = payments.aggregate(sum=Sum("amount"))["sum"] or 0
|
||||||
total_balance = total_donations - total_payments
|
total_balance = total_donations - total_payments
|
||||||
|
|
||||||
band_sum, displayed_payments = 0, []
|
band_sum, displayed_payments = 0, []
|
||||||
for pay in Payment.objects.order_by("date"):
|
for pay in payments.order_by("date"):
|
||||||
if pay.purpose.startswith("Band"):
|
if pay.purpose.startswith("Band"):
|
||||||
band_sum += pay.amount
|
band_sum += pay.amount
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user