feat: display warning alert on observation detail when linked intervention is canceled
This commit is contained in:
parent
0620f6a908
commit
cdcff04a38
4 changed files with 72 additions and 1 deletions
|
|
@ -497,6 +497,27 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body p-3 d-flex flex-column gap-3">
|
<div class="card-body p-3 d-flex flex-column gap-3">
|
||||||
|
|
||||||
|
{% if observation.intervention and observation.intervention.status == 'canceled' %}
|
||||||
|
<div class="alert alert-warning d-flex align-items-center gap-2 mb-0" role="alert">
|
||||||
|
<i class="bi bi-exclamation-triangle-fill text-warning fs-5 flex-shrink-0"></i>
|
||||||
|
<div>
|
||||||
|
<strong>{% translate "Attention :" %}</strong>
|
||||||
|
{% translate "Une intervention liée à cette observation a été annulée" %}
|
||||||
|
{% if observation.intervention.cancellation_type %}
|
||||||
|
({{ observation.intervention.get_cancellation_type_display }})
|
||||||
|
{% endif %}
|
||||||
|
:
|
||||||
|
{% if can_view_intervention_detail %}
|
||||||
|
<a href="{% url 'interventions:intervention_detail' observation.intervention.id %}" class="alert-link">
|
||||||
|
{{ observation.intervention.code }}
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<strong>{{ observation.intervention.code }}</strong>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if can_take_action and observation.status == 'to_process' %}
|
{% if can_take_action and observation.status == 'to_process' %}
|
||||||
<!-- Deux colonnes : Intervention/Projet | Statut -->
|
<!-- Deux colonnes : Intervention/Projet | Statut -->
|
||||||
<div class="d-flex flex-wrap gap-3 align-items-start">
|
<div class="d-flex flex-wrap gap-3 align-items-start">
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,27 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body p-3 d-flex flex-column gap-2">
|
<div class="card-body p-3 d-flex flex-column gap-2">
|
||||||
|
|
||||||
|
{% if observation.intervention and observation.intervention.status == 'canceled' %}
|
||||||
|
<div class="alert alert-warning d-flex align-items-center gap-2 mb-2" role="alert">
|
||||||
|
<i class="bi bi-exclamation-triangle-fill text-warning fs-5 flex-shrink-0"></i>
|
||||||
|
<div class="small">
|
||||||
|
<strong>{% translate "Attention :" %}</strong>
|
||||||
|
{% translate "Une intervention liée à cette observation a été annulée" %}
|
||||||
|
{% if observation.intervention.cancellation_type %}
|
||||||
|
({{ observation.intervention.get_cancellation_type_display }})
|
||||||
|
{% endif %}
|
||||||
|
:
|
||||||
|
{% if can_view_intervention_detail %}
|
||||||
|
<a href="{% url 'mobile:intervention_detail_mobile' observation.intervention.id %}" class="alert-link">
|
||||||
|
{{ observation.intervention.code }}
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<strong>{{ observation.intervention.code }}</strong>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<!-- Deux colonnes : Intervention/Projet | Statut -->
|
<!-- Deux colonnes : Intervention/Projet | Statut -->
|
||||||
{% if observation.status == 'to_process' %}
|
{% if observation.status == 'to_process' %}
|
||||||
{% if can_take_action %}
|
{% if can_take_action %}
|
||||||
|
|
|
||||||
|
|
@ -473,3 +473,32 @@ class ObservationPermissionTests(TestCase):
|
||||||
self.assertEqual(docs.count(), 1)
|
self.assertEqual(docs.count(), 1)
|
||||||
doc = docs.first()
|
doc = docs.first()
|
||||||
self.assertEqual(doc.uploaded_by, self.internal_user)
|
self.assertEqual(doc.uploaded_by, self.internal_user)
|
||||||
|
|
||||||
|
def test_canceled_intervention_alert_on_observation_detail(self):
|
||||||
|
from interventions.models import Intervention
|
||||||
|
intervention = Intervention.objects.create(
|
||||||
|
code="INT-TEST-CANCEL",
|
||||||
|
title="Canceled intervention test",
|
||||||
|
status="canceled",
|
||||||
|
cancellation_type="duplicate",
|
||||||
|
thematic=self.thematic_a,
|
||||||
|
lat=50.5,
|
||||||
|
lon=4.5,
|
||||||
|
)
|
||||||
|
obs = Observation.objects.create(
|
||||||
|
description="Observation with canceled intervention",
|
||||||
|
latitude=50.5,
|
||||||
|
longitude=4.5,
|
||||||
|
created_by=self.internal_user,
|
||||||
|
thematic=self.thematic_a,
|
||||||
|
status="to_process",
|
||||||
|
intervention=intervention,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.client.login(username="admin", password="pass")
|
||||||
|
detail_url = reverse("observations:observation_detail", args=[obs.id])
|
||||||
|
response = self.client.get(detail_url)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertContains(response, "Une intervention liée à cette observation a été annulée")
|
||||||
|
self.assertContains(response, "INT-TEST-CANCEL")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -655,7 +655,7 @@ def observations_export_excel(request):
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@observation_object_permission_required()
|
@observation_object_permission_required(select_related=('thematic', 'category', 'created_by', 'intervention', 'project'))
|
||||||
def observation_detail(request, observation_id):
|
def observation_detail(request, observation_id):
|
||||||
"""Detail page for a specific observation (desktop and mobile compatible)."""
|
"""Detail page for a specific observation (desktop and mobile compatible)."""
|
||||||
observation = request.observation_obj
|
observation = request.observation_obj
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue