From ae0971229e43f69491e8c36e8b8df7639300745d Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 12 Dec 2023 23:26:41 +0100 Subject: [PATCH] Fix: several errors in _get_dates_from_assi_form --- app/views/assiduites.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/views/assiduites.py b/app/views/assiduites.py index 8540b6037..f283538eb 100644 --- a/app/views/assiduites.py +++ b/app/views/assiduites.py @@ -354,6 +354,7 @@ def _get_dates_from_assi_form( try: date_debut = datetime.datetime.strptime(form.date_debut.data, "%d/%m/%Y") except ValueError: + date_debut = None form.date_debut.errors.append("date début invalide") ok = False try: @@ -363,6 +364,7 @@ def _get_dates_from_assi_form( else None ) except ValueError: + date_fin = None form.date_fin.errors.append("date fin invalide") ok = False @@ -384,11 +386,17 @@ def _get_dates_from_assi_form( form.heure_fin.errors.append("heure fin invalide") ok = False # Vérifie cohérence des dates/heures - dt_debut = datetime.datetime.combine(date_debut, heure_debut) - dt_fin = datetime.datetime.combine(date_fin or date_debut, heure_fin) - if dt_fin <= dt_debut: + dt_debut = ( + datetime.datetime.combine(date_debut, heure_debut) if date_debut else None + ) + dt_fin = ( + datetime.datetime.combine(date_fin or date_debut, heure_fin) + if (date_fin or date_debut) + else None + ) + if ok and dt_fin <= dt_debut: form.errors["general_errors"] = ["Erreur: dates début/fin incohérentes"] - return False + ok = False # La date de dépot (si vide, la date actuelle) dt_entry_date = ( datetime.datetime.strptime(form.entry_date.data, "%d/%m/%Y") @@ -396,8 +404,8 @@ def _get_dates_from_assi_form( else None ) # Ajoute time zone serveur - dt_debut_tz_server = scu.TIME_ZONE.localize(dt_debut) - dt_fin_tz_server = scu.TIME_ZONE.localize(dt_fin) + dt_debut_tz_server = scu.TIME_ZONE.localize(dt_debut) if dt_debut else None + dt_fin_tz_server = scu.TIME_ZONE.localize(dt_fin) if dt_fin else None dt_entry_date_tz_server = ( scu.TIME_ZONE.localize(dt_entry_date) if dt_entry_date else None )