mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-28 11:52:50 +02:00
Make the payment group button work
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -460,9 +460,10 @@ class PaymentUpdateView(LoginRequiredMixin, UpdateView):
|
||||
data=self.request.POST or None,
|
||||
instance=self.object)
|
||||
|
||||
context['scholarship_form'] = PaymentForm(payment_type='scholarship',
|
||||
data=self.request.POST or None,
|
||||
instance=self.object)
|
||||
if not self.object.grouped:
|
||||
context['scholarship_form'] = PaymentForm(payment_type='scholarship',
|
||||
data=self.request.POST or None,
|
||||
instance=self.object)
|
||||
|
||||
context['other_form'] = PaymentForm(payment_type='other',
|
||||
data=self.request.POST or None,
|
||||
@ -481,6 +482,54 @@ class PaymentUpdateView(LoginRequiredMixin, UpdateView):
|
||||
return reverse_lazy("registration:user_detail", args=(self.object.registrations.first().user.pk,))
|
||||
|
||||
|
||||
class PaymentUpdateGroupView(LoginRequiredMixin, DetailView):
|
||||
model = Payment
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not self.request.user.is_authenticated or \
|
||||
not self.request.user.registration.is_admin \
|
||||
and (self.request.user.registration not in self.get_object().registrations.all()
|
||||
or self.get_object().valid is not False):
|
||||
return self.handle_no_permission()
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
payment = self.get_object()
|
||||
|
||||
if payment.valid is not False:
|
||||
raise PermissionDenied(_("This payment is already valid or pending validation."))
|
||||
|
||||
if payment.grouped:
|
||||
registrations = list(payment.registrations.all())
|
||||
first_reg = registrations[0]
|
||||
payment.registrations.set([first_reg])
|
||||
payment.grouped = False
|
||||
tournament = first_reg.team.participation.tournament if not payment.final else Tournament.final_tournament()
|
||||
payment.amount = tournament.price
|
||||
payment.save()
|
||||
for registration in registrations[1:]:
|
||||
p = Payment.objects.create(type=payment.type,
|
||||
grouped=False,
|
||||
final=payment.final,
|
||||
amount=tournament.price,
|
||||
receipt=payment.receipt,
|
||||
additional_information=payment.additional_information)
|
||||
p.registrations.set([registration])
|
||||
p.save()
|
||||
else:
|
||||
reg = payment.registrations.get()
|
||||
tournament = reg.team.participation.tournament if not payment.final else Tournament.final_tournament()
|
||||
for student in reg.team.students.all():
|
||||
if student != reg:
|
||||
Payment.objects.filter(registrations=student, final=payment.final).delete()
|
||||
payment.registrations.add(student)
|
||||
payment.amount = tournament.price * reg.team.students.count()
|
||||
payment.grouped = True
|
||||
payment.save()
|
||||
|
||||
return redirect(reverse_lazy("registration:update_payment", args=(payment.pk,)))
|
||||
|
||||
|
||||
class PhotoAuthorizationView(LoginRequiredMixin, View):
|
||||
"""
|
||||
Display the sent photo authorization.
|
||||
|
Reference in New Issue
Block a user