diff --git a/itou/approvals/admin.py b/itou/approvals/admin.py index dce4455582c..69224db8464 100644 --- a/itou/approvals/admin.py +++ b/itou/approvals/admin.py @@ -232,7 +232,7 @@ class ApprovalAdmin(InconsistencyCheckMixin, ItouModelAdmin): "origin_sender_kind", "origin_siae_kind", "origin_siae_siret", - "remainder", + "get_remainder_display", ) fieldsets = ( ( @@ -242,7 +242,7 @@ class ApprovalAdmin(InconsistencyCheckMixin, ItouModelAdmin): "number", "start_at", "end_at", - "remainder", + "get_remainder_display", "user", "eligibility_diagnosis", "assigned_company", @@ -391,10 +391,6 @@ def assigned_company(self, obj): ) return "-" - @admin.display(description="Reliquat") - def remainder(self, obj): - return f"{obj.remainder.days} jour{pluralizefr(obj.duration.days)}" - class IsInProgressFilter(admin.SimpleListFilter): title = "En cours" diff --git a/itou/approvals/models.py b/itou/approvals/models.py index b23b019d22a..a5fe49388a3 100644 --- a/itou/approvals/models.py +++ b/itou/approvals/models.py @@ -27,6 +27,7 @@ from itou.utils.apis.pole_emploi import DATE_FORMAT, PoleEmploiAPIBadResponse, PoleEmploiAPIException from itou.utils.db import or_queries from itou.utils.models import DateRange +from itou.utils.templatetags.str_filters import pluralizefr from itou.utils.validators import alphanumeric, validate_siret from . import enums, notifications @@ -134,6 +135,28 @@ def _get_obj_remainder(self, obj): datetime.timedelta(0), ) - max(obj.start_at - timezone.localdate(), datetime.timedelta(0)) + def _get_human_readable_estimate(self, days): + split = [] + years = days // 365 + if years: + split.append(f"{years} an{pluralizefr(years)}") + days = days % 365 + months = days // 30 + if months: + split.append(f"{months} mois") + if years: + return "Environ " + " et ".join(split) + days = days % 30 + weeks = days // 7 + if weeks: + split.append(f"{weeks} semaine{pluralizefr(weeks)}") + if months: + return "Environ " + " et ".join(split) + days = days % 7 + if days: + split.append(f"{days} jour{pluralizefr(days)}") + return " et ".join(split) + @cached_property def remainder(self): """ @@ -149,6 +172,14 @@ def remainder(self): ) return result + def get_remainder_display(self): + remainder_display = f"{self.remainder.days} jour{pluralizefr(self.remainder.days)}" + if self.remainder.days: + remainder_display += f" ({self._get_human_readable_estimate(self.remainder.days)})" + return remainder_display + + get_remainder_display.short_description = "Reliquat" + @property def remainder_as_date(self): """ diff --git a/itou/templates/approvals/email/deliver_body.txt b/itou/templates/approvals/email/deliver_body.txt index 44ad02c1bfc..03605e924a6 100644 --- a/itou/templates/approvals/email/deliver_body.txt +++ b/itou/templates/approvals/email/deliver_body.txt @@ -5,7 +5,7 @@ Merci d'avoir confirmé l'embauche d'un candidat sur les emplois de l'inclusion. Vous trouverez ci-dessous votre PASS IAE (il équivaut à l'agrément Pôle emploi conformément aux articles L 5132-1 à L 5132-17 du code du travail) : PASS IAE N° : {{ job_application.approval.number_with_spaces }} -Nombre de jours restants sur le PASS IAE débutant le {{ job_application.approval.start_at|date:"d/m/Y" }} : {{ job_application.approval.remainder.days }} jours*. +Nombre de jours restants sur le PASS IAE débutant le {{ job_application.approval.start_at|date:"d/m/Y" }} : {{ job_application.approval.get_remainder_display }}*. Délivré pour l'embauche de : Nom : {{ job_application.approval.user.last_name|upper }} diff --git a/itou/templates/approvals/includes/list_card.html b/itou/templates/approvals/includes/list_card.html index f4b6dc9659c..707f25d4d73 100644 --- a/itou/templates/approvals/includes/list_card.html +++ b/itou/templates/approvals/includes/list_card.html @@ -49,13 +49,7 @@

{{ 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 @@

Date de début : {{ common_approval.start_at|date:"d/m/Y" }}