mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-07-20 16:09:12 +02:00
Add fee field to WEIRegistration to be able to sort on validation status
This commit is contained in:
@ -13,7 +13,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db import transaction
|
||||
from django.db.models import Q, Count
|
||||
from django.db.models import Q, Count, Case, When, Value, IntegerField, F
|
||||
from django.db.models.functions.text import Lower
|
||||
from django import forms
|
||||
from django.http import HttpResponse, Http404
|
||||
@ -133,6 +133,23 @@ class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, MultiTableMixin, D
|
||||
membership=None,
|
||||
wei=club
|
||||
)
|
||||
# Annotate the query to be able to sort registrations on validate status
|
||||
pre_registrations = pre_registrations.annotate(
|
||||
deposit=Case(
|
||||
When(deposit_type='note', then=F('wei__deposit_amount')),
|
||||
default=Value(0),
|
||||
output_field=IntegerField()
|
||||
)
|
||||
).annotate(
|
||||
total_fee=F('fee') + F('deposit')
|
||||
).annotate(
|
||||
validate_status=Case(
|
||||
When(total_fee__gt=F('user__note__balance'), then=Value(2)),
|
||||
When(first_year=True, then=Value(1)),
|
||||
default=Value(0),
|
||||
output_field=IntegerField(),
|
||||
)
|
||||
)
|
||||
buses = Bus.objects.filter(PermissionBackend.filter_queryset(self.request, Bus, "view")) \
|
||||
.filter(wei=self.object).annotate(count=Count("memberships")).order_by("name")
|
||||
return [club_transactions, club_member, pre_registrations, buses, ]
|
||||
@ -261,6 +278,23 @@ class WEIRegistrationsView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTable
|
||||
def get_queryset(self, **kwargs):
|
||||
qs = super().get_queryset(**kwargs).filter(wei=self.club, membership=None).distinct()
|
||||
|
||||
qs = qs.annotate(
|
||||
deposit=Case(
|
||||
When(deposit_type='note', then=F('wei__deposit_amount')),
|
||||
default=Value(0),
|
||||
output_field=IntegerField()
|
||||
)
|
||||
).annotate(
|
||||
total_fee=F('fee') + F('deposit')
|
||||
).annotate(
|
||||
validate_status=Case(
|
||||
When(total_fee__gt=F('user__note__balance'), then=Value(2)),
|
||||
When(first_year=True, then=Value(1)),
|
||||
default=Value(0),
|
||||
output_field=IntegerField(),
|
||||
)
|
||||
)
|
||||
|
||||
pattern = self.request.GET.get("search", "")
|
||||
|
||||
if pattern:
|
||||
@ -963,9 +997,9 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
|
||||
form = context["form"]
|
||||
if registration.soge_credit:
|
||||
form.fields["credit_amount"].initial = registration.fee
|
||||
form.fields["credit_amount"].initial = fee
|
||||
else:
|
||||
form.fields["credit_amount"].initial = max(0, registration.fee - registration.user.note.balance)
|
||||
form.fields["credit_amount"].initial = max(0, fee - registration.user.note.balance)
|
||||
|
||||
return context
|
||||
|
||||
@ -1052,7 +1086,7 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
|
||||
fee = club.membership_fee_paid if user.profile.paid else club.membership_fee_unpaid
|
||||
if registration.soge_credit:
|
||||
fee = 2000
|
||||
fee = registration.wei.fee_soge_credit
|
||||
|
||||
kfet = club.parent_club
|
||||
bde = kfet.parent_club
|
||||
|
Reference in New Issue
Block a user