From f9537e74f18ce903dde4c759b00be5fc2d4b18dc Mon Sep 17 00:00:00 2001 From: root Date: Thu, 20 Aug 2026 20:10:58 +0000 Subject: [PATCH] Corriger les champs et le calcul des horaires --- .../templates/planning/time_tracking.html | 4 ++-- app_new/planning/time_tracking.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app_new/planning/templates/planning/time_tracking.html b/app_new/planning/templates/planning/time_tracking.html index 3291693..b0d941d 100644 --- a/app_new/planning/templates/planning/time_tracking.html +++ b/app_new/planning/templates/planning/time_tracking.html @@ -26,8 +26,8 @@
Horaires types (maximum 6){{ templates|length }}/6
- {% for template in templates %}
{{ template.name }}
{{ template.start_time.strftime('%H:%M') }}–{{ template.end_time.strftime('%H:%M') }}{% if template.lunch_start %} · pause {{ template.lunch_start.strftime('%H:%M') }}–{{ template.lunch_end.strftime('%H:%M') }}{% endif %} · durée : {{ template.duration_minutes // 60 }} h {{ '%02d'|format(template.duration_minutes % 60) }}
{% else %}

Aucun profil défini.

{% endfor %} - {% if templates|length < 6 %}
{% endif %} + {% for template in templates %}
{{ template.name }}
{{ template.start_time.strftime('%H:%M') }}–{{ template.end_time.strftime('%H:%M') }}{% if template.lunch_start %} · pause {{ template.lunch_start.strftime('%H:%M') }}–{{ template.lunch_end.strftime('%H:%M') }}{% endif %} · durée : {{ template.duration_minutes // 60 }} h {{ '%02d'|format(template.duration_minutes % 60) }}
{% else %}

Aucun profil défini.

{% endfor %} + {% if templates|length < 6 %}
{% endif %}
diff --git a/app_new/planning/time_tracking.py b/app_new/planning/time_tracking.py index fd09351..ef97e30 100644 --- a/app_new/planning/time_tracking.py +++ b/app_new/planning/time_tracking.py @@ -25,6 +25,16 @@ def _minutes(start, end, lunch_start=None, lunch_end=None): return max(value, 0) +def _valid_schedule(start, end, lunch_start=None, lunch_end=None): + if not start or not end or end <= start: + return False + if bool(lunch_start) != bool(lunch_end): + return False + if lunch_start and (lunch_start < start or lunch_end > end or lunch_end <= lunch_start): + return False + return _minutes(start, end, lunch_start, lunch_end) > 0 + + def _redirect(year=None): return redirect(url_for("planning.time_tracking", year=year or _current_year())) @@ -196,8 +206,8 @@ def save_time_template(): return _redirect() start, end = _time(request.form.get("start_time")), _time(request.form.get("end_time")) lunch_start, lunch_end = _time(request.form.get("lunch_start")), _time(request.form.get("lunch_end")) - if _minutes(start, end, lunch_start, lunch_end) <= 0: - flash("Les horaires saisis sont invalides.", "danger") + if not _valid_schedule(start, end, lunch_start, lunch_end): + flash("Horaires invalides : la fin doit être après le début et la pause doit être complète et comprise dans la journée.", "danger") return _redirect() template = WorkScheduleTemplate( user_id=current_user.id, name=(request.form.get("name") or f"Horaire {count + 1}").strip(), @@ -228,8 +238,8 @@ def edit_time_template(id): start, end = _time(request.form.get("start_time")), _time(request.form.get("end_time")) lunch_start = _time(request.form.get("lunch_start")) lunch_end = _time(request.form.get("lunch_end")) or template.lunch_end - if _minutes(start, end, lunch_start, lunch_end) <= 0: - flash("Les horaires saisis sont invalides.", "danger") + if not _valid_schedule(start, end, lunch_start, lunch_end): + flash("Horaires invalides : la fin doit être après le début et la pause doit être complète et comprise dans la journée.", "danger") return _redirect() template.name = (request.form.get("name") or template.name).strip() template.start_time, template.end_time = start, end