feat: Ajout d'un nouveau status avec envoi de mandat SEPA + envoi de

mail
This commit is contained in:
N3WT DE COMPET
2025-04-11 20:02:03 +02:00
parent 4f774c18e4
commit 4c2e2f8756
17 changed files with 415 additions and 81 deletions

View File

@ -1,7 +1,6 @@
from django.http.response import JsonResponse
from django.views.decorators.csrf import ensure_csrf_cookie, csrf_protect
from django.utils.decorators import method_decorator
from rest_framework.parsers import JSONParser
from rest_framework.views import APIView
from rest_framework.decorators import action, api_view
from rest_framework import status
@ -230,10 +229,16 @@ class RegisterFormWithIdView(APIView):
"""
Modifie un dossier d'inscription donné.
"""
studentForm_data = JSONParser().parse(request)
# Récupérer les données de la requête
studentForm_data = request.data.copy()
logger.info(f"Mise à jour du dossier d'inscription {studentForm_data}")
_status = studentForm_data.pop('status', 0)
studentForm_data["last_update"] = str(util.convertToStr(util._now(), '%d-%m-%Y %H:%M'))
if isinstance(_status, list): # Cas Multipart/data, les données sont envoyées sous forme de liste, c'est nul
_status = int(_status[0])
else:
_status = int(_status)
# Récupérer le dossier d'inscription
registerForm = bdd.getObject(_objectName=RegistrationForm, _columnName='student__id', _value=id)
@ -282,6 +287,17 @@ class RegisterFormWithIdView(APIView):
if registerForm.status == RegistrationForm.RegistrationFormStatus.RF_UNDER_REVIEW:
updateStateMachine(registerForm, 'EVENT_REFUSE')
util.delete_registration_files(registerForm)
elif _status == RegistrationForm.RegistrationFormStatus.RF_SEPA_SENT:
# Sauvegarde du mandat SEPA
student = registerForm.student
guardian = student.getMainGuardian()
email = guardian.profile_role.profile.email
errorMessage = mailer.sendMandatSEPA(email, registerForm.establishment.pk)
if errorMessage == '':
registerForm.last_update=util.convertToStr(util._now(), '%d-%m-%Y %H:%M')
updateStateMachine(registerForm, 'EVENT_SEND_SEPA')
return JsonResponse({"message": f"Le mandat SEPA a bien été envoyé à l'addresse {email}"}, safe=False)
return JsonResponse({"errorMessage":errorMessage}, safe=False, status=status.HTTP_400_BAD_REQUEST)
# Retourner les données mises à jour
return JsonResponse(studentForm_serializer.data, safe=False)