diff --git a/website/payments/templates/payments/payment_list.html b/website/payments/templates/payments/payment_list.html index fc4f860fb..eabab2fbb 100644 --- a/website/payments/templates/payments/payment_list.html +++ b/website/payments/templates/payments/payment_list.html @@ -16,7 +16,7 @@
{% endif %} {% if object_list %} diff --git a/website/payments/views.py b/website/payments/views.py index 577c9c560..3114293a2 100644 --- a/website/payments/views.py +++ b/website/payments/views.py @@ -1,4 +1,5 @@ from decimal import Decimal +from itertools import groupby from django.apps import apps from django.conf import settings @@ -144,15 +145,27 @@ def get_queryset(self) -> QuerySet: ) def get_context_data(self, *args, **kwargs): + current_time = timezone.now().replace(tzinfo=None) + nr_months = 0 + earliest_membership = self.request.member.earliest_membership + difference = relativedelta(current_time, earliest_membership.since) + nr_months = difference.years * 12 + difference.months + 1 + filters = [] - for i in range(13): + for i in range(min(nr_months, 85)): new_now = timezone.now() - relativedelta(months=i) filters.append({"year": new_now.year, "month": new_now.month}) + initial_filters = filters[:6] + year_filters = [] + for key, group in groupby(filters[6:], lambda f: f["year"]): + year_filters.append({"year": key, "months": list(group)}) + context = super().get_context_data(*args, **kwargs) context.update( { - "filters": filters, + "initial_filters": initial_filters, + "year_filters": year_filters, "total": context["object_list"] .aggregate(Sum("amount")) .get("amount__sum"),