Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra dropdowns for every year in payment history #3840

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions website/payments/templates/payments/payment_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,31 @@ <h5 class="mb-4">
</h5>
{% endif %}
<ul class="nav nav-tabs mb-4">
{% for filter in filters|slice:':6' %}
{% for filter in initial_filters %}
<li class="nav-item">
<a class="nav-link {% if filter.year == year and filter.month == month %}active{% endif %}"
href="{% url 'payments:payment-list' filter.year filter.month %}">
{{ filter.year }}-{{ filter.month|stringformat:"02d" }}
</a>
</li>
{% endfor %}
{% for filter_group in year_filters %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle {% if filters.6.year == year and filters.6.month >= month or filters.6.year > year and filters.6.month < month %}active{% endif %}"
data-bs-toggle="dropdown"
data-bs-display="static"
href="#" role="button" aria-haspopup="true"
aria-expanded="false">{% trans 'Older' %}</a>
aria-expanded="false">{{ filter_group.year }}</a>
<div class="dropdown-menu">
{% for filter in filters|slice:'6:' %}
{% for filter in filter_group.months %}
<a class="dropdown-item {% if filter.year == year and filter.month == month %}active{% endif %}"
href="{% url 'payments:payment-list' filter.year filter.month %}">
{{ filter.year }}-{{ filter.month|stringformat:"02d" }}
</a>
{% endfor %}
</div>
</li>
{% endfor %}
</ul>
{% if object_list %}
<table class="table">
Expand Down
17 changes: 15 additions & 2 deletions website/payments/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from decimal import Decimal
from itertools import groupby

from django.apps import apps
from django.conf import settings
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This crashes if a user with no memberships tries to open it:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion that I think does not break code coverage: add if earliest_membership else None to the end of this line, and do the same but with else 0 for nr_months

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"),
Expand Down
Loading