feat: add asset interventions list component to asset detail view

This commit is contained in:
kdeterme 2026-08-07 11:33:29 +02:00
parent c74e96bf29
commit 286c3e07f2
3 changed files with 131 additions and 0 deletions

View file

@ -0,0 +1,89 @@
{% load i18n %}
{# Interventions liées à l'asset #}
<div class="card mb-3" id="asset-interventions-card">
<div class="card-header bg-light d-flex align-items-center justify-content-between">
<h5 class="mb-0">
<i class="bi bi-wrench-adjustable me-2"></i>{% translate "Interventions liées" %}
{% if interventions %}
<span class="badge bg-secondary rounded-pill ms-1">{{ interventions|length }}</span>
{% endif %}
</h5>
</div>
<div class="card-body p-0">
{% if interventions %}
<div class="table-responsive">
<table class="table table-hover table-sm mb-0 align-middle">
<thead class="table-light">
<tr>
<th style="width: 12%;" class="ps-3">{% translate "Code" %}</th>
<th style="width: 25%;">{% translate "Titre" %}</th>
<th style="width: 18%;">{% translate "Symptôme" %}</th>
<th style="width: 15%;">{% translate "Statut" %}</th>
<th style="width: 10%;">{% translate "Priorité" %}</th>
<th style="width: 12%;">{% translate "Attribué à" %}</th>
<th style="width: 8%;" class="pe-3">{% translate "Date" %}</th>
</tr>
</thead>
<tbody>
{% for intervention in interventions %}
<tr>
<td class="ps-3">
<a href="{% url 'interventions:intervention_detail' intervention.id %}" class="fw-bold text-decoration-none">
{{ intervention.code }}
</a>
</td>
<td>
<a href="{% url 'interventions:intervention_detail' intervention.id %}" class="text-reset text-decoration-none">
{{ intervention.title }}
</a>
</td>
<td>
{% if intervention.symptom %}
{{ intervention.symptom.get_name }}
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
<span class="badge" style="background-color: {{ intervention.status_color_hex }}; color: {{ intervention.status_text_color_hex }};">
{{ intervention.get_status_display }}
</span>
</td>
<td>
{% if intervention.priority == '1' %}
<span class="badge bg-danger">{{ intervention.get_priority_display }}</span>
{% elif intervention.priority == '2' %}
<span class="badge bg-warning text-dark">{{ intervention.get_priority_display }}</span>
{% elif intervention.priority == '3' %}
<span class="badge bg-secondary">{{ intervention.get_priority_display }}</span>
{% elif intervention.priority == '4' %}
<span class="badge bg-light text-dark border">{{ intervention.get_priority_display }}</span>
{% else %}
<span class="badge bg-secondary">{{ intervention.get_priority_display|default:"-" }}</span>
{% endif %}
</td>
<td>
{% if intervention.assigned_team %}
<span class="small">{{ intervention.assigned_team.name }}</span>
{% elif intervention.assigned_provider %}
<span class="small">{{ intervention.assigned_provider.name }}</span>
{% else %}
<span class="text-muted small">-</span>
{% endif %}
</td>
<td class="pe-3">
<small class="text-muted">{{ intervention.creation_time|date:"d/m/Y" }}</small>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="p-3 text-muted">
<i class="bi bi-info-circle me-1"></i>{% translate "Aucune intervention liée à cet asset." %}
</div>
{% endif %}
</div>
</div>

View file

@ -726,6 +726,13 @@
</div>
</div>
<!-- Interventions liées (pleine largeur) -->
<div class="row mt-3">
<div class="col-12">
{% asset_interventions asset %}
</div>
</div>
<!-- Historique des modifications (plein largeur, en bas) -->
<div class="row mt-3">
<div class="col-12">

View file

@ -436,3 +436,38 @@ def warranty_remaining_months(asset):
remaining = (warranty_end.year - now.year) * 12 + (warranty_end.month - now.month)
return remaining
@register.inclusion_tag('assets/components/asset_interventions.html')
def asset_interventions(asset):
"""
Display all interventions associated with an asset.
"""
if asset is None or not hasattr(asset, 'pk') or asset.pk is None:
return {
'asset': asset,
'interventions': [],
}
from django.contrib.contenttypes.models import ContentType
from interventions.models import Intervention, InterventionAsset, STATUS_COLORS, STATUS_COLORS_DARK_TEXT
asset_ct = ContentType.objects.get_for_model(asset)
intervention_ids = InterventionAsset.objects.filter(
content_type=asset_ct,
object_id=asset.pk
).values_list('intervention_id', flat=True)
interventions = list(Intervention.objects.filter(
pk__in=intervention_ids
).select_related(
'symptom', 'contract', 'assigned_provider', 'assigned_team', 'created_by'
).order_by('-creation_time'))
return {
'asset': asset,
'interventions': interventions,
'status_colors': STATUS_COLORS,
'status_colors_dark_text': STATUS_COLORS_DARK_TEXT,
}