From e4e538d26843a62035c63128e7e86554046f0893 Mon Sep 17 00:00:00 2001
From: Antoine LAURENT Date de début : {{ common_approval.start_at|date:"d/m/Y" }}{{ approval.user.get_full_name }}
-
- {% if approval.is_valid %}
- {{ approval.remainder.days }} jour{{ approval.remainder.days|pluralizefr }}
- {% else %}
- 0 jour
- {% endif %}
-
+ {{ approval.get_remainder_display }}
diff --git a/itou/templates/approvals/includes/status.html b/itou/templates/approvals/includes/status.html
index f0291e17a63..e7f2f815fb2 100644
--- a/itou/templates/approvals/includes/status.html
+++ b/itou/templates/approvals/includes/status.html
@@ -53,7 +53,7 @@
un PASS IAE pour un parcours d'insertion par l'activité économique,
conformément aux dispositions des articles L 5132-1 à L 5132-17 du code du travail.
Nombre de jours restants sur le PASS IAE : {{ approval.remainder.days }} jours*.
+Nombre de jours restants sur le PASS IAE : {{ approval.get_remainder_display }}*.
* Le reliquat est calculé sur la base d’un nombre de jours calendaires. Si le PASS IAE n'est pas suspendu, il décroit donc tous les jours (samedi, dimanche et jours fériés compris). diff --git a/tests/approvals/tests.py b/tests/approvals/tests.py index 856d94b6151..c08c644a2f1 100644 --- a/tests/approvals/tests.py +++ b/tests/approvals/tests.py @@ -529,6 +529,7 @@ def test_remainder(self): end_at=datetime.date(2023, 3, 24), ) assert approval.remainder == datetime.timedelta(days=123) + assert approval.get_remainder_display() == "123 jours (Environ 4 mois)" # Futur prolongation, adding 4 days to approval.end_date. ProlongationFactory( @@ -553,6 +554,7 @@ def test_remainder(self): approval.refresh_from_db() prolonged_remainder = 123 + 4 + 5 + 30 assert approval.remainder == datetime.timedelta(days=prolonged_remainder) + assert approval.get_remainder_display() == "162 jours (Environ 5 mois et 1 semaine)" # Past suspension (ignored), adding 5 days to approval.end_date. SuspensionFactory( @@ -571,6 +573,21 @@ def test_remainder(self): approval.refresh_from_db() # Substract to remainder the remaining suspension time assert approval.remainder == datetime.timedelta(days=(prolonged_remainder + 5 + 30 - 10)) + assert approval.get_remainder_display() == "187 jours (Environ 6 mois et 1 semaine)" + + def test_human_readable_estimate(self): + assert Approval()._get_human_readable_estimate(730) == "Environ 2 ans" + assert Approval()._get_human_readable_estimate(705) == "Environ 1 an et 11 mois" + assert Approval()._get_human_readable_estimate(380) == "Environ 1 an" + assert Approval()._get_human_readable_estimate(235) == "Environ 7 mois et 3 semaines" + assert Approval()._get_human_readable_estimate(158) == "Environ 5 mois et 1 semaine" + assert Approval()._get_human_readable_estimate(121) == "Environ 4 mois" + assert Approval()._get_human_readable_estimate(15) == "2 semaines et 1 jour" + assert Approval()._get_human_readable_estimate(14) == "2 semaines" + assert Approval()._get_human_readable_estimate(13) == "1 semaine et 6 jours" + assert Approval()._get_human_readable_estimate(7) == "1 semaine" + assert Approval()._get_human_readable_estimate(6) == "6 jours" + assert Approval()._get_human_readable_estimate(1) == "1 jour" @freeze_time("2023-04-26") def test_remainder_as_date(self): @@ -730,12 +747,12 @@ def test_is_valid(self): assert approval.is_valid() @freeze_time("2022-11-22") - def test_remainder(self): + def test_get_remainder_display(self): pole_emploi_approval = PoleEmploiApprovalFactory( start_at=datetime.date(2021, 3, 25), end_at=datetime.date(2023, 3, 24), ) - assert pole_emploi_approval.remainder == datetime.timedelta(days=123) + assert pole_emploi_approval.get_remainder_display() == "123 jours (Environ 4 mois)" class PoleEmploiApprovalManagerTest(TestCase): diff --git a/tests/job_applications/tests.py b/tests/job_applications/tests.py index a6b82d3b2b5..e9ca2b26044 100644 --- a/tests/job_applications/tests.py +++ b/tests/job_applications/tests.py @@ -1036,7 +1036,7 @@ def test_notifications_deliver_approval(self): assert approval.user.get_full_name() in email.subject assert approval.number_with_spaces in email.body assert approval.start_at.strftime("%d/%m/%Y") in email.body - assert f"{approval.remainder.days} jours" in email.body + assert approval.get_remainder_display() in email.body assert approval.user.last_name.upper() in email.body assert approval.user.first_name.title() in email.body assert approval.user.birthdate.strftime("%d/%m/%Y") in email.body diff --git a/tests/www/approvals_views/__snapshots__/test_includes.ambr b/tests/www/approvals_views/__snapshots__/test_includes.ambr index ebb2e7159a1..3b27009d48e 100644 --- a/tests/www/approvals_views/__snapshots__/test_includes.ambr +++ b/tests/www/approvals_views/__snapshots__/test_includes.ambr @@ -208,7 +208,7 @@
Date de début : 01/01/2000
Date de début : 01/01/2000
Date de début : 01/01/2000