feat: Ajout d'un nouvel état dans l'automatique lorsqu'un mandat SEPA

doit être envoyé aux parent
This commit is contained in:
N3WT DE COMPET
2025-04-27 13:40:48 +02:00
parent 3c62cc9ad2
commit 545349c7db
14 changed files with 214 additions and 153 deletions

View File

@ -30,6 +30,16 @@
"from": "SENT",
"to": "UNDER_REVIEW"
},
{
"name": "EVENT_WAITING_FOR_SEPA",
"from": "SENT",
"to": "SEPA_TO_SEND"
},
{
"name": "EVENT_SEND_SEPA",
"from": "SEPA_TO_SEND",
"to": "SEPA_SENT"
},
{
"name": "EVENT_FOLLOW_UP",
"from": "SENT",
@ -55,11 +65,6 @@
"from": "UNDER_REVIEW",
"to": "VALIDATED"
},
{
"name": "EVENT_SEND_SEPA",
"from": "UNDER_REVIEW",
"to": "SEPA_SENT"
},
{
"name": "EVENT_ARCHIVE",
"from": "UNDER_REVIEW",

View File

@ -10,7 +10,8 @@ state_mapping = {
"TO_BE_FOLLOWED_UP": RegistrationForm.RegistrationFormStatus.RF_TO_BE_FOLLOWED_UP,
"VALIDATED": RegistrationForm.RegistrationFormStatus.RF_VALIDATED,
"ARCHIVED": RegistrationForm.RegistrationFormStatus.RF_ARCHIVED,
"SEPA_SENT": RegistrationForm.RegistrationFormStatus.RF_SEPA_SENT
"SEPA_SENT": RegistrationForm.RegistrationFormStatus.RF_SEPA_SENT,
"SEPA_TO_SEND": RegistrationForm.RegistrationFormStatus.RF_SEPA_TO_SEND
}
def load_config(config_file):

View File

@ -182,6 +182,7 @@ class RegistrationForm(models.Model):
RF_VALIDATED = 5, _('Dossier d\'inscription validé')
RF_ARCHIVED = 6, _('Dossier d\'inscription archivé')
RF_SEPA_SENT = 7, _('Mandat SEPA envoyé')
RF_SEPA_TO_SEND = 8, _('Mandat SEPA à envoyer')
# One-to-One Relationship
student = models.OneToOneField(Student, on_delete=models.CASCADE, primary_key=True)

View File

@ -252,6 +252,8 @@ class RegisterFormWithIdView(APIView):
return JsonResponse(studentForm_serializer.errors, safe=False, status=status.HTTP_400_BAD_REQUEST)
if _status == RegistrationForm.RegistrationFormStatus.RF_UNDER_REVIEW:
# Le parent a rempli le dossier d'inscription sans sélectionner "Prélèvement par Mandat SEPA"
# L'école doit désormais valider le dossier d'inscription
try:
# Génération de la fiche d'inscription au format PDF
base_dir = os.path.join(settings.MEDIA_ROOT, f"registration_files/dossier_rf_{registerForm.pk}")
@ -304,11 +306,14 @@ class RegisterFormWithIdView(APIView):
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'adresse {email}"}, safe=False)
return JsonResponse({"errorMessage": errorMessage}, safe=False, status=status.HTTP_400_BAD_REQUEST)
if errorMessage != '':
return JsonResponse({"errorMessage": errorMessage}, safe=False, status=status.HTTP_400_BAD_REQUEST)
registerForm.last_update = util.convertToStr(util._now(), '%d-%m-%Y %H:%M')
updateStateMachine(registerForm, 'EVENT_SEND_SEPA')
elif _status == RegistrationForm.RegistrationFormStatus.RF_SEPA_TO_SEND:
# Le parent a rempli le dossier d'inscription en sélectionnant "Prélèvement par Mandat SEPA"
# L'école doit désormais envoyer le mandat SEPA pour poursuivre l'inscription
updateStateMachine(registerForm, 'EVENT_WAITING_FOR_SEPA')
# Retourner les données mises à jour
return JsonResponse(studentForm_serializer.data, safe=False)

View File

@ -101,7 +101,8 @@ class ChildrenListView(APIView):
status__in=[
RegistrationForm.RegistrationFormStatus.RF_SENT,
RegistrationForm.RegistrationFormStatus.RF_UNDER_REVIEW,
RegistrationForm.RegistrationFormStatus.RF_SEPA_SENT
RegistrationForm.RegistrationFormStatus.RF_SEPA_SENT,
RegistrationForm.RegistrationFormStatus.RF_SEPA_TO_SEND
]
).distinct()
students_serializer = RegistrationFormByParentSerializer(students, many=True)