mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 01:58:23 +02:00
Restructure payment model
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
@ -14,7 +14,7 @@ from django.utils import timezone
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from registration.models import VolunteerRegistration, Payment
|
||||
from registration.models import Payment, VolunteerRegistration
|
||||
from tfjm.lists import get_sympa_client
|
||||
|
||||
|
||||
@ -465,14 +465,15 @@ class Participation(models.Model):
|
||||
def important_informations(self):
|
||||
informations = []
|
||||
|
||||
missing_payments = Payment.objects.filter(registration__in=self.team.participants.all(), valid=False)
|
||||
missing_payments = Payment.objects.filter(registrations__in=self.team.participants.all(), valid=False)
|
||||
if missing_payments.exists():
|
||||
text = _("<p>The team {trigram} has {nb_missing_payments} missing payments. Each member of the team "
|
||||
"must have a valid payment (or send a scholarship notification) "
|
||||
"to participate to the tournament.</p>"
|
||||
"<p>Participants that have not paid yet are: {participants}.</p>")
|
||||
content = format_lazy(text, trigram=self.team.trigram, nb_missing_payments=missing_payments.count(),
|
||||
participants=", ".join(str(p.registration) for p in missing_payments.all()))
|
||||
participants=", ".join(", ".join(str(r) for r in p.registrations.all())
|
||||
for p in missing_payments.all()))
|
||||
informations.append({
|
||||
'title': _("Missing payments"),
|
||||
'type': "danger",
|
||||
|
@ -30,7 +30,7 @@ from odf.opendocument import OpenDocumentSpreadsheet
|
||||
from odf.style import Style, TableCellProperties, TableColumnProperties, TextProperties
|
||||
from odf.table import CoveredTableCell, Table, TableCell, TableColumn, TableRow
|
||||
from odf.text import P
|
||||
from registration.models import StudentRegistration, VolunteerRegistration
|
||||
from registration.models import Payment, StudentRegistration, VolunteerRegistration
|
||||
from tfjm.lists import get_sympa_client
|
||||
from tfjm.views import AdminMixin, VolunteerMixin
|
||||
|
||||
@ -246,16 +246,20 @@ class TeamDetailView(LoginRequiredMixin, FormMixin, ProcessFormView, DetailView)
|
||||
mail_html = render_to_string("participation/mails/team_validated.html", mail_context)
|
||||
send_mail("[TFJM²] Équipe validée", mail_plain, None, [self.object.email], html_message=mail_html)
|
||||
|
||||
if self.object.participation.tournament.price == 0:
|
||||
for registration in self.object.participants.all():
|
||||
registration.payment.type = "free"
|
||||
registration.payment.valid = True
|
||||
registration.payment.save()
|
||||
else:
|
||||
for coach in self.object.coaches.all():
|
||||
coach.payment.type = "free"
|
||||
coach.payment.valid = True
|
||||
coach.payment.save()
|
||||
for student in self.object.students.all():
|
||||
payment_qs = Payment.objects.filter(registrations=student)
|
||||
if payment_qs.exists():
|
||||
payment = payment_qs.get()
|
||||
else:
|
||||
payment = Payment.objects.create()
|
||||
payment.registrations.add(student)
|
||||
payment.save()
|
||||
payment.amount = self.object.participation.tournament.price
|
||||
if payment.amount == 0:
|
||||
payment.type = "free"
|
||||
payment.valid = True
|
||||
payment.save()
|
||||
|
||||
elif "invalidate" in self.request.POST:
|
||||
self.object.participation.valid = None
|
||||
self.object.participation.save()
|
||||
|
Reference in New Issue
Block a user