From 0697211ac7951cd98aa04d60316147e11efae334 Mon Sep 17 00:00:00 2001 From: bpc Date: Wed, 13 Nov 2024 23:21:08 +0100 Subject: [PATCH 1/6] Add extra dropdowns for every year in payment history --- .../payments/templates/payments/payment_list.html | 9 ++++++--- website/payments/views.py | 12 ++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) 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..3aed3e22b 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 @@ -145,14 +146,21 @@ def get_queryset(self) -> QuerySet: def get_context_data(self, *args, **kwargs): filters = [] - for i in range(13): + + for i in range(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"), From 95e0490ff4fe8bb1eb42f174777ef097a71ca23c Mon Sep 17 00:00:00 2001 From: bpc Date: Wed, 11 Dec 2024 20:35:22 +0100 Subject: [PATCH 2/6] Changed so that you can see you payment history since you have been a member or 7 years depends on which one is the later date. --- website/payments/views.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/website/payments/views.py b/website/payments/views.py index 3aed3e22b..ce0337e0e 100644 --- a/website/payments/views.py +++ b/website/payments/views.py @@ -1,5 +1,7 @@ +import datetime from decimal import Decimal from itertools import groupby +import time from django.apps import apps from django.conf import settings @@ -24,6 +26,7 @@ from dateutil.relativedelta import relativedelta +from members.models import member from payments import services from payments.exceptions import PaymentError from payments.forms import BankAccountForm, BankAccountUserRevokeForm, PaymentCreateForm @@ -145,9 +148,18 @@ def get_queryset(self) -> QuerySet: ) def get_context_data(self, *args, **kwargs): - filters = [] + earliest_membership = PaymentUser.objects.get( + pk=self.request.member.pk + ).earliest_membership.since + if ( + earliest_membership + and earliest_membership > (timezone.now() - relativedelta(years=7)).date() + ): + difference = relativedelta(timezone.now(), earliest_membership) + months = difference.years * 12 + difference.months + 1 - for i in range(85): + filters = [] + for i in range(min(months, 85)): new_now = timezone.now() - relativedelta(months=i) filters.append({"year": new_now.year, "month": new_now.month}) From 910ade9cf139d2d2c7d2a30195864216eba4b8b4 Mon Sep 17 00:00:00 2001 From: bpc Date: Wed, 11 Dec 2024 20:35:47 +0100 Subject: [PATCH 3/6] Changed so that you can see you payment history since you have been a member or 7 years depends on which one is the later date. --- website/payments/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/website/payments/views.py b/website/payments/views.py index ce0337e0e..30bff4637 100644 --- a/website/payments/views.py +++ b/website/payments/views.py @@ -148,14 +148,15 @@ def get_queryset(self) -> QuerySet: ) def get_context_data(self, *args, **kwargs): + current_time = timezone.now().replace(tzinfo=None) earliest_membership = PaymentUser.objects.get( pk=self.request.member.pk ).earliest_membership.since if ( earliest_membership - and earliest_membership > (timezone.now() - relativedelta(years=7)).date() + and earliest_membership > (current_time - relativedelta(years=7)).date() ): - difference = relativedelta(timezone.now(), earliest_membership) + difference = relativedelta(current_time, earliest_membership) months = difference.years * 12 + difference.months + 1 filters = [] From 807337761dadcd6d9dc9faa67fcc881d44d4b7f2 Mon Sep 17 00:00:00 2001 From: bpc Date: Wed, 11 Dec 2024 20:41:47 +0100 Subject: [PATCH 4/6] fixed some ruff issues --- website/payments/views.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/website/payments/views.py b/website/payments/views.py index 30bff4637..10fc6617d 100644 --- a/website/payments/views.py +++ b/website/payments/views.py @@ -1,7 +1,5 @@ -import datetime from decimal import Decimal from itertools import groupby -import time from django.apps import apps from django.conf import settings @@ -26,7 +24,6 @@ from dateutil.relativedelta import relativedelta -from members.models import member from payments import services from payments.exceptions import PaymentError from payments.forms import BankAccountForm, BankAccountUserRevokeForm, PaymentCreateForm From 9e2767ecb882a99e44f56ea3c8241138b8a0712e Mon Sep 17 00:00:00 2001 From: bpc Date: Wed, 11 Dec 2024 20:45:25 +0100 Subject: [PATCH 5/6] Fixed test? --- website/payments/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/payments/views.py b/website/payments/views.py index 10fc6617d..5161017d0 100644 --- a/website/payments/views.py +++ b/website/payments/views.py @@ -154,10 +154,10 @@ def get_context_data(self, *args, **kwargs): and earliest_membership > (current_time - relativedelta(years=7)).date() ): difference = relativedelta(current_time, earliest_membership) - months = difference.years * 12 + difference.months + 1 + nr_months = difference.years * 12 + difference.months + 1 filters = [] - for i in range(min(months, 85)): + 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}) From f77261007e46df247d6d9ce60840f9d7e6bb51ca Mon Sep 17 00:00:00 2001 From: bpc Date: Wed, 11 Dec 2024 20:49:00 +0100 Subject: [PATCH 6/6] Assigned value to nr_months by default --- website/payments/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/website/payments/views.py b/website/payments/views.py index 5161017d0..9efcede8a 100644 --- a/website/payments/views.py +++ b/website/payments/views.py @@ -146,6 +146,7 @@ def get_queryset(self) -> QuerySet: def get_context_data(self, *args, **kwargs): current_time = timezone.now().replace(tzinfo=None) + nr_months = 0 earliest_membership = PaymentUser.objects.get( pk=self.request.member.pk ).earliest_membership.since