mirror of https://gitlab.crans.org/bde/nk20
Factorize detection of uncomplete payment forms
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
parent
8f895dc4d7
commit
c3ab61bd04
|
@ -625,9 +625,6 @@ class ClubAddMemberView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||||
# Retrieve form data
|
# Retrieve form data
|
||||||
credit_type = form.cleaned_data["credit_type"]
|
credit_type = form.cleaned_data["credit_type"]
|
||||||
credit_amount = form.cleaned_data["credit_amount"]
|
credit_amount = form.cleaned_data["credit_amount"]
|
||||||
last_name = form.cleaned_data["last_name"]
|
|
||||||
first_name = form.cleaned_data["first_name"]
|
|
||||||
bank = form.cleaned_data["bank"]
|
|
||||||
soge = form.cleaned_data["soge"] and not user.profile.soge and (club.name == "BDE" or club.name == "Kfet")
|
soge = form.cleaned_data["soge"] and not user.profile.soge and (club.name == "BDE" or club.name == "Kfet")
|
||||||
|
|
||||||
if not credit_type:
|
if not credit_type:
|
||||||
|
@ -675,16 +672,8 @@ class ClubAddMemberView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||||
error = True
|
error = True
|
||||||
|
|
||||||
if credit_amount:
|
if credit_amount:
|
||||||
if not last_name or not first_name or (not bank and credit_type.special_type == "Chèque"):
|
# Check that special information for payment are filled
|
||||||
if not last_name:
|
error = SpecialTransaction.validate_payment_form(form) or error
|
||||||
form.add_error('last_name', _("This field is required."))
|
|
||||||
error = True
|
|
||||||
if not first_name:
|
|
||||||
form.add_error('first_name', _("This field is required."))
|
|
||||||
error = True
|
|
||||||
if not bank and credit_type.special_type == "Chèque":
|
|
||||||
form.add_error('bank', _("This field is required."))
|
|
||||||
error = True
|
|
||||||
|
|
||||||
return not error
|
return not error
|
||||||
|
|
||||||
|
|
|
@ -333,6 +333,36 @@ class SpecialTransaction(Transaction):
|
||||||
self.clean()
|
self.clean()
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def validate_payment_form(form):
|
||||||
|
"""
|
||||||
|
Ensure that last name and first name are filled for a form that creates a SpecialTransaction,
|
||||||
|
and check that if the user pays with a check, then the bank field is filled.
|
||||||
|
|
||||||
|
Return True iff there is no error.
|
||||||
|
Whenever there is an error, they are inserted in the form errors.
|
||||||
|
"""
|
||||||
|
|
||||||
|
credit_type = form.cleaned_data["credit_type"]
|
||||||
|
last_name = form.cleaned_data["last_name"]
|
||||||
|
first_name = form.cleaned_data["first_name"]
|
||||||
|
bank = form.cleaned_data["bank"]
|
||||||
|
|
||||||
|
error = True
|
||||||
|
|
||||||
|
if not last_name or not first_name or (not bank and credit_type.special_type == "Chèque"):
|
||||||
|
if not last_name:
|
||||||
|
form.add_error('last_name', _("This field is required."))
|
||||||
|
error = True
|
||||||
|
if not first_name:
|
||||||
|
form.add_error('first_name', _("This field is required."))
|
||||||
|
error = True
|
||||||
|
if not bank and credit_type.special_type == "Chèque":
|
||||||
|
form.add_error('bank', _("This field is required."))
|
||||||
|
error = True
|
||||||
|
|
||||||
|
return not error
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("Special transaction")
|
verbose_name = _("Special transaction")
|
||||||
verbose_name_plural = _("Special transactions")
|
verbose_name_plural = _("Special transactions")
|
||||||
|
|
|
@ -248,9 +248,13 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, FormMixin,
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
"""
|
||||||
|
Finally validate the registration, with creating the membership.
|
||||||
|
"""
|
||||||
user = self.get_object()
|
user = self.get_object()
|
||||||
|
|
||||||
if Alias.objects.filter(normalized_name=Alias.normalize(user.username)).exists():
|
if Alias.objects.filter(normalized_name=Alias.normalize(user.username)).exists():
|
||||||
|
# Don't try to hack an existing account.
|
||||||
form.add_error(None, _("An alias with a similar name already exists."))
|
form.add_error(None, _("An alias with a similar name already exists."))
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
@ -265,14 +269,16 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, FormMixin,
|
||||||
join_kfet = form.cleaned_data["join_kfet"]
|
join_kfet = form.cleaned_data["join_kfet"]
|
||||||
|
|
||||||
if soge:
|
if soge:
|
||||||
# If Société Générale pays the inscription, the user joins the two clubs
|
# If Société Générale pays the inscription, the user automatically joins the two clubs.
|
||||||
join_bde = True
|
join_bde = True
|
||||||
join_kfet = True
|
join_kfet = True
|
||||||
|
|
||||||
if not join_bde:
|
if not join_bde:
|
||||||
|
# This software belongs to the BDE.
|
||||||
form.add_error('join_bde', _("You must join the BDE."))
|
form.add_error('join_bde', _("You must join the BDE."))
|
||||||
return super().form_invalid(form)
|
return super().form_invalid(form)
|
||||||
|
|
||||||
|
# Calculate required registration fee
|
||||||
fee = 0
|
fee = 0
|
||||||
bde = Club.objects.get(name="BDE")
|
bde = Club.objects.get(name="BDE")
|
||||||
bde_fee = bde.membership_fee_paid if user.profile.paid else bde.membership_fee_unpaid
|
bde_fee = bde.membership_fee_paid if user.profile.paid else bde.membership_fee_unpaid
|
||||||
|
@ -298,14 +304,8 @@ class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, FormMixin,
|
||||||
.format(pretty_money(fee)))
|
.format(pretty_money(fee)))
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
if credit_type is not None and credit_amount > 0:
|
# Check that payment information are filled, like last name and first name
|
||||||
if not last_name or not first_name or (not bank and credit_type.special_type == "Chèque"):
|
if credit_type is not None and credit_amount > 0 and SpecialTransaction.validate_payment_form(form):
|
||||||
if not last_name:
|
|
||||||
form.add_error('last_name', _("This field is required."))
|
|
||||||
if not first_name:
|
|
||||||
form.add_error('first_name', _("This field is required."))
|
|
||||||
if not bank and credit_type.special_type == "Chèque":
|
|
||||||
form.add_error('bank', _("This field is required."))
|
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
# Save the user and finally validate the registration
|
# Save the user and finally validate the registration
|
||||||
|
|
Loading…
Reference in New Issue