mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-12-23 07:52:23 +00:00
Validate WEI memberships
This commit is contained in:
parent
36b26e0baa
commit
db67598b25
@ -544,6 +544,8 @@ class ClubAddMemberView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
|
||||
valid=True,
|
||||
)
|
||||
|
||||
ret = super().form_valid(form)
|
||||
|
||||
# If Société générale pays, then we store the information: the bank can't pay twice to a same person.
|
||||
if soge:
|
||||
user.profile.soge = True
|
||||
@ -573,7 +575,7 @@ class ClubAddMemberView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
|
||||
membership.roles.add(Role.objects.get(name="Adhérent Kfet"))
|
||||
membership.save()
|
||||
|
||||
return super().form_valid(form)
|
||||
return ret
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('member:club_detail', kwargs={'pk': self.object.club.id})
|
||||
|
@ -7,7 +7,7 @@ from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from member.models import Role, Club, Membership
|
||||
from note.models import NoteSpecial
|
||||
from note.models import NoteSpecial, MembershipTransaction
|
||||
|
||||
|
||||
class WEIClub(Club):
|
||||
@ -268,3 +268,23 @@ class WEIMembership(Membership):
|
||||
class Meta:
|
||||
verbose_name = _("WEI membership")
|
||||
verbose_name_plural = _("WEI memberships")
|
||||
|
||||
def make_transaction(self):
|
||||
"""
|
||||
Create Membership transaction associated to this membership.
|
||||
"""
|
||||
if not self.fee or MembershipTransaction.objects.filter(membership=self).exists():
|
||||
return
|
||||
|
||||
if self.fee:
|
||||
transaction = MembershipTransaction(
|
||||
membership=self,
|
||||
source=self.user.note,
|
||||
destination=self.club.note,
|
||||
quantity=1,
|
||||
amount=self.fee,
|
||||
reason="Adhésion WEI " + self.club.name,
|
||||
valid=not self.registration.soge_credit # Soge transactions are by default invalidated
|
||||
)
|
||||
transaction._force_save = True
|
||||
transaction.save(force_insert=True)
|
||||
|
@ -1,13 +1,14 @@
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, date
|
||||
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models import Q
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import DetailView, UpdateView, CreateView
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django_tables2 import SingleTableView
|
||||
from member.models import Membership, Club
|
||||
from note.models import Transaction, NoteClub
|
||||
@ -302,9 +303,54 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Crea
|
||||
context["club"] = registration.wei
|
||||
context["fee"] = registration.wei.membership_fee_paid if registration.user.profile.paid \
|
||||
else registration.wei.membership_fee_unpaid
|
||||
context["kfet_member"] = Membership.objects.filter(
|
||||
club__name="Kfet",
|
||||
user=registration.user,
|
||||
date_start__lte=datetime.now().date(),
|
||||
date_end__gte=datetime.now().date(),
|
||||
).exists()
|
||||
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
"""
|
||||
Create membership, check that all is good, make transactions
|
||||
"""
|
||||
registration = WEIRegistration.objects.get(pk=self.kwargs["pk"])
|
||||
club = registration.wei
|
||||
user = registration.user
|
||||
|
||||
membership = form.instance
|
||||
membership.user = user
|
||||
membership.club = club
|
||||
membership.date_start = min(date.today(), club.date_start)
|
||||
membership.registration = registration
|
||||
|
||||
if user.profile.paid:
|
||||
fee = club.membership_fee_paid
|
||||
else:
|
||||
fee = club.membership_fee_unpaid
|
||||
|
||||
if not registration.soge_credit and user.note.balance < fee:
|
||||
# Users must have money before registering to the WEI.
|
||||
# TODO Send a notification to the user (with a mail?) to tell her/him to credit her/his note
|
||||
form.add_error('bus',
|
||||
_("This user don't have enough money to join this club, and can't have a negative balance."))
|
||||
return super().form_invalid(form)
|
||||
|
||||
if not registration.caution_check and True: # TODO: Replace it with "is 2A+"
|
||||
form.add_error('bus', _("This user didn't give her/his caution check."))
|
||||
return super().form_invalid(form)
|
||||
|
||||
if club.parent_club is not None:
|
||||
if not Membership.objects.filter(user=form.instance.user, club=club.parent_club).exists():
|
||||
form.add_error('user', _('User is not a member of the parent club') + ' ' + club.parent_club.name)
|
||||
return super().form_invalid(form)
|
||||
|
||||
# Now, all is fine, the membership can be created.
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_success_url(self):
|
||||
self.object.refresh_from_db()
|
||||
return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.wei.pk})
|
||||
return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.club.pk})
|
||||
|
@ -121,6 +121,19 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if not kfet_member %}
|
||||
<div class="alert alert-danger">
|
||||
{% url 'registration:future_user_detail' pk=registration.user.pk as future_user_detail %}
|
||||
{% url 'member:club_detail' pk=club.parent_club.parent_club.pk as club_detail %}
|
||||
{% blocktrans %}
|
||||
This user is not a member of the Kfet club. Please adhere
|
||||
<a href="{{ future_user_detail }}">here if he/she is in her/his first year</a>
|
||||
or <a href="{{ club_detail }}">here if he/she was an old member</a> before you validate
|
||||
the registration of the WEI.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card-body" id="profile_infos">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
|
Loading…
Reference in New Issue
Block a user