From e1238860028cb7b50374214fb197ac34d1d10659 Mon Sep 17 00:00:00 2001 From: Ewen Corre Date: Mon, 9 Sep 2024 17:44:31 +0200 Subject: [PATCH] feat(employee_record.admin): link on approval number --- itou/employee_record/admin.py | 12 ++++++++++-- tests/employee_record/test_admin.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/itou/employee_record/admin.py b/itou/employee_record/admin.py index e611681e07..44325f4b60 100644 --- a/itou/employee_record/admin.py +++ b/itou/employee_record/admin.py @@ -2,7 +2,9 @@ from django import forms from django.contrib import admin, messages +from django.urls import reverse from django.utils import timezone +from django.utils.html import format_html import itou.employee_record.models as models from itou.companies import models as companies_models @@ -159,7 +161,7 @@ def schedule_approval_update_notification(self, request, queryset): "created_at", "updated_at", "processed_at", - "approval_number", + "approval_number_link", "job_application", "job_seeker_link", "job_seeker_profile_link", @@ -197,7 +199,7 @@ def schedule_approval_update_notification(self, request, queryset): "pk", "status", "job_application", - "approval_number", + "approval_number_link", "job_seeker_link", "job_seeker_profile_link", "siret", @@ -228,6 +230,12 @@ def schedule_approval_update_notification(self, request, queryset): ), ) + @admin.display(description="numéro d'agrément") + def approval_number_link(self, obj): + if approval_number := obj.approval_number: + url = reverse("admin:approvals_approval_change", args=(obj.job_application.approval_id,)) + return format_html('{}', url, approval_number) + @admin.display(description="salarié") def job_seeker_link(self, obj): if job_seeker := obj.job_application.job_seeker: diff --git a/tests/employee_record/test_admin.py b/tests/employee_record/test_admin.py index fad88455ff..133679555f 100644 --- a/tests/employee_record/test_admin.py +++ b/tests/employee_record/test_admin.py @@ -4,6 +4,7 @@ from django.urls import reverse from pytest_django.asserts import assertContains, assertMessages +from itou.approvals.models import Approval from itou.employee_record import models from tests.employee_record import factories @@ -68,3 +69,12 @@ def test_job_seeker_profile_from_employee_record(admin_client): response = admin_client.get(employee_record_view_url) assertContains(response, "Profil salarié") assertContains(response, job_seeker.jobseeker_profile.pk) + + +def test_approval_number_from_employee_record(admin_client): + er = factories.EmployeeRecordFactory() + approval_number = Approval.objects.get(number=er.approval_number) + employee_record_view_url = reverse("admin:employee_record_employeerecord_change", args=[er.pk]) + approval_number_url = reverse("admin:approvals_approval_change", args=[approval_number.pk]) + response = admin_client.get(employee_record_view_url) + assertContains(response, f'{approval_number.number}')