1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-23 07:52:23 +00:00

[WEI] Validate WEI memberships of first year members before the repartition algorithm to debit notes

Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
Yohann D'ANELLO 2021-09-10 22:09:47 +02:00
parent 49551e88f8
commit 3532846c87
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
5 changed files with 121 additions and 97 deletions

View File

@ -1,10 +1,10 @@
# Copyright (C) 2018-2021 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from .registration import WEIForm, WEIRegistrationForm, WEIMembershipForm, BusForm, BusTeamForm
from .registration import WEIForm, WEIRegistrationForm, WEIMembership1AForm, WEIMembershipForm, BusForm, BusTeamForm
from .surveys import WEISurvey, WEISurveyInformation, WEISurveyAlgorithm, CurrentSurvey
__all__ = [
'WEIForm', 'WEIRegistrationForm', 'WEIMembershipForm', 'BusForm', 'BusTeamForm',
'WEIForm', 'WEIRegistrationForm', 'WEIMembesrhip1AForm', 'WEIMembershipForm', 'BusForm', 'BusTeamForm',
'WEISurvey', 'WEISurveyInformation', 'WEISurveyAlgorithm', 'CurrentSurvey',
]

View File

@ -144,6 +144,20 @@ class WEIMembershipForm(forms.ModelForm):
}
class WEIMembership1AForm(WEIMembershipForm):
"""
Used to confirm registrations of first year members without choosing a bus now.
"""
roles = None
def clean(self):
return super(forms.ModelForm, self).clean()
class Meta:
model = WEIMembership
fields = ('credit_type', 'credit_amount', 'last_name', 'first_name', 'bank',)
class BusForm(forms.ModelForm):
class Meta:
model = Bus

View File

@ -102,9 +102,9 @@ class WEIRegistrationTable(tables.Table):
if record.fee > record.user.note.balance and not record.soge_credit:
btn_class = 'btn-secondary'
tooltip = _("The user does not have enough money.")
elif record.first_year and 'selected_bus_pk' not in record.information:
elif record.first_year:
btn_class = 'btn-info'
tooltip = _("The user is in first year, and the repartition algorithm didn't run.")
tooltip = _("The user is in first year. You may validate the credit, the algorithm will run later.")
else:
btn_class = 'btn-success'
tooltip = _("The user has enough money, you can validate the registration.")

View File

@ -32,7 +32,8 @@ from permission.views import ProtectQuerysetMixin, ProtectedCreateView
from .forms.registration import WEIChooseBusForm
from .models import WEIClub, WEIRegistration, WEIMembership, Bus, BusTeam, WEIRole
from .forms import WEIForm, WEIRegistrationForm, BusForm, BusTeamForm, WEIMembershipForm, CurrentSurvey
from .forms import WEIForm, WEIRegistrationForm, BusForm, BusTeamForm, WEIMembership1AForm, \
WEIMembershipForm, CurrentSurvey
from .tables import WEITable, WEIRegistrationTable, BusTable, BusTeamTable, WEIMembershipTable
@ -799,7 +800,6 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
Validate WEI Registration
"""
model = WEIMembership
form_class = WEIMembershipForm
extra_context = {"title": _("Validate WEI registration")}
def get_sample_object(self):
@ -855,6 +855,12 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
return context
def get_form_class(self):
registration = WEIRegistration.objects.get(pk=self.kwargs["pk"])
if registration.first_year and 'sleected_bus_pk' not in registration.information:
return WEIMembership1AForm
return WEIMembershipForm
def get_form(self, form_class=None):
form = super().get_form(form_class)
registration = WEIRegistration.objects.get(pk=self.kwargs["pk"])
@ -870,25 +876,27 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
form.fields["bank"].disabled = True
form.fields["bank"].initial = "Société générale"
form.fields["bus"].widget.attrs["api_url"] = "/api/wei/bus/?wei=" + str(registration.wei.pk)
if registration.first_year:
# Use the results of the survey to fill initial data
# A first year has no other role than "1A"
del form.fields["roles"]
survey = CurrentSurvey(registration)
if survey.information.valid:
form.fields["bus"].initial = survey.information.get_selected_bus()
else:
# Use the choice of the member to fill initial data
information = registration.information
if "preferred_bus_pk" in information and len(information["preferred_bus_pk"]) == 1:
form["bus"].initial = Bus.objects.get(pk=information["preferred_bus_pk"][0])
if "preferred_team_pk" in information and len(information["preferred_team_pk"]) == 1:
form["team"].initial = BusTeam.objects.get(pk=information["preferred_team_pk"][0])
if "preferred_roles_pk" in information:
form["roles"].initial = WEIRole.objects.filter(
Q(pk__in=information["preferred_roles_pk"]) | Q(name="Adhérent WEI")
).all()
if 'bus' in form.fields:
# For 2A+ and hardcoded 1A
form.fields["bus"].widget.attrs["api_url"] = "/api/wei/bus/?wei=" + str(registration.wei.pk)
if registration.first_year:
# Use the results of the survey to fill initial data
# A first year has no other role than "1A"
del form.fields["roles"]
survey = CurrentSurvey(registration)
if survey.information.valid:
form.fields["bus"].initial = survey.information.get_selected_bus()
else:
# Use the choice of the member to fill initial data
information = registration.information
if "preferred_bus_pk" in information and len(information["preferred_bus_pk"]) == 1:
form["bus"].initial = Bus.objects.get(pk=information["preferred_bus_pk"][0])
if "preferred_team_pk" in information and len(information["preferred_team_pk"]) == 1:
form["team"].initial = BusTeam.objects.get(pk=information["preferred_team_pk"][0])
if "preferred_roles_pk" in information:
form["roles"].initial = WEIRole.objects.filter(
Q(pk__in=information["preferred_roles_pk"]) | Q(name="Adhérent WEI")
).all()
return form
@transaction.atomic

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-08 18:46+0200\n"
"POT-Creation-Date: 2021-09-10 22:08+0200\n"
"PO-Revision-Date: 2020-11-16 20:02+0000\n"
"Last-Translator: Yohann D'ANELLO <ynerant@crans.org>\n"
"Language-Team: French <http://translate.ynerant.fr/projects/nk20/nk20/fr/>\n"
@ -111,7 +111,7 @@ msgid "type"
msgstr "type"
#: apps/activity/models.py:89 apps/logs/models.py:22 apps/member/models.py:305
#: apps/note/models/notes.py:148 apps/treasury/models.py:286
#: apps/note/models/notes.py:148 apps/treasury/models.py:285
#: apps/wei/models.py:165 apps/wei/templates/wei/survey.html:15
msgid "user"
msgstr "utilisateur"
@ -251,7 +251,7 @@ msgstr "Entré le "
msgid "remove"
msgstr "supprimer"
#: apps/activity/tables.py:80 apps/note/forms.py:68 apps/treasury/models.py:200
#: apps/activity/tables.py:80 apps/note/forms.py:68 apps/treasury/models.py:199
msgid "Type"
msgstr "Type"
@ -1188,7 +1188,7 @@ msgstr "Modifier le club"
msgid "Add new member to the club"
msgstr "Ajouter un nouveau membre au club"
#: apps/member/views.py:642 apps/wei/views.py:932
#: apps/member/views.py:642 apps/wei/views.py:952
msgid ""
"This user don't have enough money to join this club, and can't have a "
"negative balance."
@ -1494,8 +1494,8 @@ msgstr ""
"mode de paiement et un utilisateur ou un club"
#: apps/note/models/transactions.py:355 apps/note/models/transactions.py:358
#: apps/note/models/transactions.py:361 apps/wei/views.py:937
#: apps/wei/views.py:941
#: apps/note/models/transactions.py:361 apps/wei/views.py:957
#: apps/wei/views.py:961
msgid "This field is required."
msgstr "Ce champ est requis."
@ -1511,7 +1511,7 @@ msgstr "Transactions de crédit/retrait"
msgid "membership transaction"
msgstr "transaction d'adhésion"
#: apps/note/models/transactions.py:385 apps/treasury/models.py:293
#: apps/note/models/transactions.py:385 apps/treasury/models.py:292
msgid "membership transactions"
msgstr "transactions d'adhésion"
@ -1625,7 +1625,7 @@ msgid "Amount"
msgstr "Montant"
#: apps/note/templates/note/transaction_form.html:128
#: apps/treasury/models.py:55
#: apps/treasury/models.py:54
msgid "Name"
msgstr "Nom"
@ -2102,7 +2102,7 @@ msgstr "Invalider l'inscription"
msgid "Treasury"
msgstr "Trésorerie"
#: apps/treasury/forms.py:26 apps/treasury/models.py:94
#: apps/treasury/forms.py:26 apps/treasury/models.py:93
#: apps/treasury/templates/treasury/invoice_form.html:22
msgid "This invoice is locked and can no longer be edited."
msgstr "Cette facture est verrouillée et ne peut plus être éditée."
@ -2115,7 +2115,7 @@ msgstr "La remise est déjà fermée."
msgid "You can't change the type of the remittance."
msgstr "Vous ne pouvez pas changer le type de la remise."
#: apps/treasury/forms.py:125 apps/treasury/models.py:268
#: apps/treasury/forms.py:125 apps/treasury/models.py:267
#: apps/treasury/tables.py:97 apps/treasury/tables.py:105
#: apps/treasury/templates/treasury/invoice_list.html:16
#: apps/treasury/templates/treasury/remittance_list.html:16
@ -2127,120 +2127,120 @@ msgstr "Remise"
msgid "No attached remittance"
msgstr "Pas de remise associée"
#: apps/treasury/models.py:27
#: apps/treasury/models.py:26
msgid "Invoice identifier"
msgstr "Numéro de facture"
#: apps/treasury/models.py:41
#: apps/treasury/models.py:40
msgid "BDE"
msgstr "BDE"
#: apps/treasury/models.py:46
#: apps/treasury/models.py:45
msgid "Object"
msgstr "Objet"
#: apps/treasury/models.py:50
#: apps/treasury/models.py:49
msgid "Description"
msgstr "Description"
#: apps/treasury/models.py:59
#: apps/treasury/models.py:58
msgid "Address"
msgstr "Adresse"
#: apps/treasury/models.py:64 apps/treasury/models.py:194
#: apps/treasury/models.py:63 apps/treasury/models.py:193
msgid "Date"
msgstr "Date"
#: apps/treasury/models.py:68
#: apps/treasury/models.py:67
msgid "Acquitted"
msgstr "Acquittée"
#: apps/treasury/models.py:73
#: apps/treasury/models.py:72
msgid "Locked"
msgstr "Verrouillée"
#: apps/treasury/models.py:74
#: apps/treasury/models.py:73
msgid "An invoice can't be edited when it is locked."
msgstr "Une facture ne peut plus être modifiée si elle est verrouillée."
#: apps/treasury/models.py:80
#: apps/treasury/models.py:79
msgid "tex source"
msgstr "fichier TeX source"
#: apps/treasury/models.py:114 apps/treasury/models.py:130
#: apps/treasury/models.py:113 apps/treasury/models.py:129
msgid "invoice"
msgstr "facture"
#: apps/treasury/models.py:115
#: apps/treasury/models.py:114
msgid "invoices"
msgstr "factures"
#: apps/treasury/models.py:118
#: apps/treasury/models.py:117
#, python-brace-format
msgid "Invoice #{id}"
msgstr "Facture n°{id}"
#: apps/treasury/models.py:135
#: apps/treasury/models.py:134
msgid "Designation"
msgstr "Désignation"
#: apps/treasury/models.py:141
#: apps/treasury/models.py:140
msgid "Quantity"
msgstr "Quantité"
#: apps/treasury/models.py:146
#: apps/treasury/models.py:145
msgid "Unit price"
msgstr "Prix unitaire"
#: apps/treasury/models.py:162
#: apps/treasury/models.py:161
msgid "product"
msgstr "produit"
#: apps/treasury/models.py:163
#: apps/treasury/models.py:162
msgid "products"
msgstr "produits"
#: apps/treasury/models.py:183
#: apps/treasury/models.py:182
msgid "remittance type"
msgstr "type de remise"
#: apps/treasury/models.py:184
#: apps/treasury/models.py:183
msgid "remittance types"
msgstr "types de remises"
#: apps/treasury/models.py:205
#: apps/treasury/models.py:204
msgid "Comment"
msgstr "Commentaire"
#: apps/treasury/models.py:210
#: apps/treasury/models.py:209
msgid "Closed"
msgstr "Fermée"
#: apps/treasury/models.py:214
#: apps/treasury/models.py:213
msgid "remittance"
msgstr "remise"
#: apps/treasury/models.py:215
#: apps/treasury/models.py:214
msgid "remittances"
msgstr "remises"
#: apps/treasury/models.py:248
#: apps/treasury/models.py:247
msgid "Remittance #{:d}: {}"
msgstr "Remise n°{:d} : {}"
#: apps/treasury/models.py:272
#: apps/treasury/models.py:271
msgid "special transaction proxy"
msgstr "proxy de transaction spéciale"
#: apps/treasury/models.py:273
#: apps/treasury/models.py:272
msgid "special transaction proxies"
msgstr "proxys de transactions spéciales"
#: apps/treasury/models.py:299
#: apps/treasury/models.py:298
msgid "credit transaction"
msgstr "transaction de crédit"
#: apps/treasury/models.py:418
#: apps/treasury/models.py:419
msgid ""
"This user doesn't have enough money to pay the memberships with its note. "
"Please ask her/him to credit the note before invalidating this credit."
@ -2248,16 +2248,16 @@ msgstr ""
"Cet utilisateur n'a pas assez d'argent pour payer les adhésions avec sa "
"note. Merci de lui demander de recharger sa note avant d'invalider ce crédit."
#: apps/treasury/models.py:438
#: apps/treasury/models.py:439
#: apps/treasury/templates/treasury/sogecredit_detail.html:10
msgid "Credit from the Société générale"
msgstr "Crédit de la Société générale"
#: apps/treasury/models.py:439
#: apps/treasury/models.py:440
msgid "Credits from the Société générale"
msgstr "Crédits de la Société générale"
#: apps/treasury/models.py:442
#: apps/treasury/models.py:443
#, python-brace-format
msgid "Soge credit for {user}"
msgstr "Crédit de la société générale pour l'utilisateur {user}"
@ -2710,10 +2710,12 @@ msgid "The user does not have enough money."
msgstr "L'utilisateur n'a pas assez d'argent."
#: apps/wei/tables.py:107
msgid "The user is in first year, and the repartition algorithm didn't run."
msgid ""
"The user is in first year. You may validate the credit, the algorithm will "
"run later."
msgstr ""
"L'utilisateur est en première année, et l'algorithme de répartition n'a pas "
"tourné."
"L'utilisateur est en première année, vous pouvez valider le crédit, "
"l'algorithme tournera plus tard."
#: apps/wei/tables.py:110
msgid "The user has enough money, you can validate the registration."
@ -2752,11 +2754,11 @@ msgstr "Prix du WEI (étudiants)"
msgid "WEI list"
msgstr "Liste des WEI"
#: apps/wei/templates/wei/base.html:81 apps/wei/views.py:517
#: apps/wei/templates/wei/base.html:81 apps/wei/views.py:523
msgid "Register 1A"
msgstr "Inscrire un 1A"
#: apps/wei/templates/wei/base.html:85 apps/wei/views.py:592
#: apps/wei/templates/wei/base.html:85 apps/wei/views.py:603
msgid "Register 2A+"
msgstr "Inscrire un 2A+"
@ -2785,8 +2787,8 @@ msgstr "Télécharger au format PDF"
#: apps/wei/templates/wei/survey.html:11
#: apps/wei/templates/wei/survey_closed.html:11
#: apps/wei/templates/wei/survey_end.html:11 apps/wei/views.py:988
#: apps/wei/views.py:1043 apps/wei/views.py:1053
#: apps/wei/templates/wei/survey_end.html:11 apps/wei/views.py:1007
#: apps/wei/views.py:1062 apps/wei/views.py:1072
msgid "Survey WEI"
msgstr "Questionnaire WEI"
@ -2827,7 +2829,7 @@ msgstr "Membres du WEI"
msgid "Unvalidated registrations"
msgstr "Inscriptions non validées"
#: apps/wei/templates/wei/weiclub_list.html:14 apps/wei/views.py:77
#: apps/wei/templates/wei/weiclub_list.html:14 apps/wei/views.py:78
msgid "Create WEI"
msgstr "Créer un WEI"
@ -2968,67 +2970,67 @@ msgstr "Il n'y a pas de pré-inscription en attente avec cette entrée."
msgid "View validated memberships..."
msgstr "Voir les adhésions validées ..."
#: apps/wei/views.py:56
#: apps/wei/views.py:57
msgid "Search WEI"
msgstr "Chercher un WEI"
#: apps/wei/views.py:107
#: apps/wei/views.py:108
msgid "WEI Detail"
msgstr "Détails du WEI"
#: apps/wei/views.py:202
#: apps/wei/views.py:203
msgid "View members of the WEI"
msgstr "Voir les membres du WEI"
#: apps/wei/views.py:230
#: apps/wei/views.py:231
msgid "Find WEI Membership"
msgstr "Trouver une adhésion au WEI"
#: apps/wei/views.py:240
#: apps/wei/views.py:241
msgid "View registrations to the WEI"
msgstr "Voir les inscriptions au WEI"
#: apps/wei/views.py:264
#: apps/wei/views.py:265
msgid "Find WEI Registration"
msgstr "Trouver une inscription au WEI"
#: apps/wei/views.py:275
#: apps/wei/views.py:276
msgid "Update the WEI"
msgstr "Modifier le WEI"
#: apps/wei/views.py:296
#: apps/wei/views.py:297
msgid "Create new bus"
msgstr "Ajouter un nouveau bus"
#: apps/wei/views.py:334
#: apps/wei/views.py:335
msgid "Update bus"
msgstr "Modifier le bus"
#: apps/wei/views.py:366
#: apps/wei/views.py:367
msgid "Manage bus"
msgstr "Gérer le bus"
#: apps/wei/views.py:393
#: apps/wei/views.py:394
msgid "Create new team"
msgstr "Créer une nouvelle équipe"
#: apps/wei/views.py:433
#: apps/wei/views.py:434
msgid "Update team"
msgstr "Modifier l'équipe"
#: apps/wei/views.py:464
#: apps/wei/views.py:465
msgid "Manage WEI team"
msgstr "Gérer l'équipe WEI"
#: apps/wei/views.py:486
#: apps/wei/views.py:487
msgid "Register first year student to the WEI"
msgstr "Inscrire un 1A au WEI"
#: apps/wei/views.py:539 apps/wei/views.py:627
#: apps/wei/views.py:545 apps/wei/views.py:638
msgid "This user is already registered to this WEI."
msgstr "Cette personne est déjà inscrite au WEI."
#: apps/wei/views.py:544
#: apps/wei/views.py:550
msgid ""
"This user can't be in her/his first year since he/she has already "
"participated to a WEI."
@ -3036,27 +3038,27 @@ msgstr ""
"Cet utilisateur ne peut pas être en première année puisqu'il a déjà "
"participé à un WEI."
#: apps/wei/views.py:561
#: apps/wei/views.py:567
msgid "Register old student to the WEI"
msgstr "Inscrire un 2A+ au WEI"
#: apps/wei/views.py:611 apps/wei/views.py:700
#: apps/wei/views.py:622 apps/wei/views.py:713
msgid "You already opened an account in the Société générale."
msgstr "Vous avez déjà ouvert un compte auprès de la société générale."
#: apps/wei/views.py:657
#: apps/wei/views.py:668
msgid "Update WEI Registration"
msgstr "Modifier l'inscription WEI"
#: apps/wei/views.py:761
#: apps/wei/views.py:774
msgid "Delete WEI registration"
msgstr "Supprimer l'inscription WEI"
#: apps/wei/views.py:772
#: apps/wei/views.py:785
msgid "You don't have the right to delete this WEI registration."
msgstr "Vous n'avez pas la permission de supprimer cette inscription au WEI."
#: apps/wei/views.py:791
#: apps/wei/views.py:803
msgid "Validate WEI registration"
msgstr "Valider l'inscription WEI"