diff --git a/loko/interventions/models.py b/loko/interventions/models.py index f3fdf00..cadd6ad 100644 --- a/loko/interventions/models.py +++ b/loko/interventions/models.py @@ -810,6 +810,40 @@ class Intervention(models.Model): status__in=['to_process', 'pending'] ).exists() + @property + def has_material(self): + """Indique si l'intervention dispose de matériel mentionné dans ses bons de préparation.""" + if not hasattr(self, 'preparation_orders'): + return False + return self.preparation_orders.filter( + Q(preparationorderitem__isnull=False) | Q(other_items__isnull=False) + ).distinct().exists() + + def get_material_stats(self): + """ + Retourne le statut d'utilisation du matériel pour cette intervention : + - total : nombre total d'articles (catalogue + autres) + - used : nombre d'articles marqués comme utilisés + - all_used : True si tous les articles sont utilisés (et total > 0) + - has_material : True si au moins un article existe + """ + if not hasattr(self, 'preparation_orders'): + return {'total': 0, 'used': 0, 'all_used': False, 'has_material': False} + from stock.models import PreparationOrderItem, PreparationOrderOtherItem + order_ids = list(self.preparation_orders.values_list('id', flat=True)) + if not order_ids: + return {'total': 0, 'used': 0, 'all_used': False, 'has_material': False} + std_items = PreparationOrderItem.objects.filter(preparation_order_id__in=order_ids) + other_items = PreparationOrderOtherItem.objects.filter(preparation_order_id__in=order_ids) + total = std_items.count() + other_items.count() + used = std_items.filter(is_used=True).count() + other_items.filter(is_used=True).count() + return { + 'total': total, + 'used': used, + 'all_used': (total > 0 and used == total), + 'has_material': total > 0, + } + def get_associated_observations(self): """ Retourne le QuerySet de toutes les observations associées à cette intervention : diff --git a/loko/interventions/templates/interventions/detail/card_stock.html b/loko/interventions/templates/interventions/detail/card_stock.html index 834b01d..25a502d 100644 --- a/loko/interventions/templates/interventions/detail/card_stock.html +++ b/loko/interventions/templates/interventions/detail/card_stock.html @@ -1,86 +1,235 @@ {% load i18n %} {% if can_create_preparation_order or preparation_orders %} -
| {% translate "Numéro" %} | -{% translate "Date" %} | -{% translate "Statut" %} | -{% translate "Articles" %} | -{% translate "Actions" %} | -
|---|---|---|---|---|
| {{ order.order_number }} | -{{ order.date|date:"d/m/Y H:i" }} | -- {% if order.status == 'to_process' %} - - {{ order.get_status_display }} - - {% elif order.status == 'pending' %} - - {{ order.get_status_display }} - - {% elif order.status == 'processed' %} - - {{ order.get_status_display }} - - {% endif %} - | -- {% with items=order.preparationorderitem_set.all %} - {% if items %} - - {% for item in items|slice:":3" %} - {{ item.product.name }} ({{ item.quantity }}){% if not forloop.last %}, {% endif %} - {% endfor %} - {% if items.count > 3 %} - ... +{{ items.count|add:"-3" }} - {% endif %} - - {% else %} - {% translate "Aucun article" %} - {% endif %} - {% endwith %} - | -- - - - | -
- - {% translate "Aucun bon de préparation créé pour cette intervention." %} -
- {% endif %} -| {% translate "Utilisé ?" %} | +{% translate "Article" %} | +{% translate "Référence" %} | +{% translate "Quantité" %} | +{% translate "Préparation" %} | +{% translate "Statut" %} | +
|---|---|---|---|---|---|
|
+
+
+
+ |
+ + {{ item.product.name }} + {% if item.product.category %} + {{ item.product.category.name_fr }} + {% endif %} + | +
+ {% if item.product.code %}
+ {{ item.product.code }}
+ {% else %}
+ —
+ {% endif %}
+ |
+ + + × {{ item.quantity }} + + | ++ {% if item.is_prepared %} + + {% translate "Préparé" %} + + {% else %} + + {% translate "En attente" %} + + {% endif %} + | ++ + {% if item.is_used %} + {% translate "Utilisé" %} + {% else %} + {% translate "Non utilisé" %} + {% endif %} + + | +
|
+
+
+
+ |
+ + {{ item.description }} + {% translate "Hors catalogue" %} + {% if item.category %} + {{ item.category.name_fr }} + {% endif %} + | ++ — + | ++ + × {{ item.quantity }} + + | ++ {% if item.is_prepared %} + + {% translate "Préparé" %} + + {% else %} + + {% translate "En attente" %} + + {% endif %} + | ++ + {% if item.is_used %} + {% translate "Utilisé" %} + {% else %} + {% translate "Non utilisé" %} + {% endif %} + + | +
+ + {% translate "Aucun bon de préparation créé pour cette intervention." %} +
+ {% endif %} +