From 5bb4e4e0eb48667632ce229184b4e472b6f03933 Mon Sep 17 00:00:00 2001 From: Iziram Date: Tue, 9 Jan 2024 14:38:02 +0100 Subject: [PATCH] Assiduites : fix bug comptage absences + invalide cache justification --- app/scodoc/sco_assiduites.py | 4 ++-- app/views/assiduites.py | 4 +++- tests/unit/test_assiduites.py | 36 ++++++++++++++++++++++++++--------- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/app/scodoc/sco_assiduites.py b/app/scodoc/sco_assiduites.py index 00bc4922d..487556aba 100644 --- a/app/scodoc/sco_assiduites.py +++ b/app/scodoc/sco_assiduites.py @@ -188,7 +188,7 @@ class CountCalculator: if assi.etat != scu.EtatAssiduite.PRESENT: _key: str = scu.EtatAssiduite.inverse().get(assi.etat).name.lower() if key not in self.data[_key]["demi"]: - self.data[_key]["demi"].append(day) + self.data[_key]["demi"].append(key) if key not in self.data["total"]["demi"]: self.data["total"]["demi"].append(key) @@ -663,7 +663,7 @@ def get_assiduites_count_in_interval( calculator: CountCalculator = CountCalculator() calculator.compute_assiduites(assiduites) - calcul : dict = calculator.to_dict(only_total=False) + calcul: dict = calculator.to_dict(only_total=False) nb_abs: dict = calcul["absent"][metrique] nb_abs_just: dict = calcul["absent_just"][metrique] diff --git a/app/views/assiduites.py b/app/views/assiduites.py index 5e1a4b0b5..73f997901 100644 --- a/app/views/assiduites.py +++ b/app/views/assiduites.py @@ -1492,7 +1492,9 @@ def tableau_assiduite_actions(): ) compute_assiduites_justified(objet.etudiant.id, [justificatif_correspondant]) - + scass.simple_invalidate_cache( + justificatif_correspondant.to_dict(), objet.etudiant.id + ) flash(f"{objet_name} justifiée") return redirect(request.referrer) diff --git a/tests/unit/test_assiduites.py b/tests/unit/test_assiduites.py index 3f2d40da4..12b34b802 100644 --- a/tests/unit/test_assiduites.py +++ b/tests/unit/test_assiduites.py @@ -1307,6 +1307,19 @@ def test_calcul_assiduites(test_client): scu.EtatAssiduite.ABSENT, False, ), + # 18/12 + ( + "12-18T08:00", + "12-18T10:00", + scu.EtatAssiduite.ABSENT, + False, + ), + ( + "12-18T10:00", + "12-18T12:00", + scu.EtatAssiduite.ABSENT, + False, + ), ] for ass in assiduites: @@ -1333,17 +1346,17 @@ def test_calcul_assiduites(test_client): resultat_attendu: dict = { "present": {"journee": 5, "demi": 8, "heure": 13.25, "compte": 9}, "absent": { - "journee": 5 + 5, - "demi": 7 + 10, - "heure": 11.25 + 42, - "compte": 7 + 1, + "journee": 6 + 5, + "demi": 8 + 10, + "heure": 15.25 + 42, + "compte": 9 + 1, }, "absent_just": {"journee": 3, "demi": 3, "heure": 4.25, "compte": 3}, "absent_non_just": { - "journee": 3 + 5, - "demi": 4 + 10, - "heure": 7 + 42, - "compte": 4 + 1, + "journee": 4 + 5, + "demi": 5 + 10, + "heure": 11 + 42, + "compte": 6 + 1, }, "retard": { "journee": 5, @@ -1353,9 +1366,14 @@ def test_calcul_assiduites(test_client): }, "retard_just": {"journee": 3, "demi": 3, "heure": 2.5, "compte": 3}, "retard_non_just": {"journee": 3, "demi": 4, "heure": 8.0, "compte": 4}, - "total": {"journee": 10, "demi": 19, "heure": 77.0, "compte": 24}, + "total": {"journee": 11, "demi": 20, "heure": 81.0, "compte": 26}, } + for key in resultat_attendu: + assert ( + resultat_attendu[key]["journee"] * 2 >= resultat_attendu[key]["demi"] + ), f"Trop de demi-journées [{key}]" + for key in resultat_attendu: for key2 in resultat_attendu[key]: assert (