From cfe242ee11167219ac412671bb743e28d8b38ed2 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 21 Aug 2026 10:32:00 +0000 Subject: [PATCH] =?UTF-8?q?R=C3=A9parer=20les=20interventions=20et=20modif?= =?UTF-8?q?ier=20leur=20localisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_new/interventions/crud.py | 35 ++++++++++- app_new/interventions/templates/detail.html | 68 +++++++++++++++++++-- 2 files changed, 97 insertions(+), 6 deletions(-) diff --git a/app_new/interventions/crud.py b/app_new/interventions/crud.py index b1f01a9..20788fe 100644 --- a/app_new/interventions/crud.py +++ b/app_new/interventions/crud.py @@ -3,7 +3,7 @@ from flask import Blueprint, render_template, redirect, url_for, request, flash, from flask_login import login_required, current_user from app_new.extensions import db from ..core.models.maintenance import Intervention, InterventionComment -from ..core.models.equipment import Equipment +from ..core.models.equipment import Equipment, EquipmentCategory from ..core.models.user import User from datetime import datetime @@ -109,7 +109,6 @@ def index(): lots=lots, users=users, statuses=INTERVENTION_STATUSES, - workflow_status_order=WORKFLOW_STATUS_ORDERS.get(intervention.workflow_type, WORKFLOW_STATUS_ORDERS['corrective']), workflow_types=WORKFLOW_TYPES, priorities=PRIORITIES, status_counts=status_counts, @@ -410,6 +409,10 @@ def detail(id): statuses=INTERVENTION_STATUSES, transitions=transitions, history=history, + workflow_status_order=WORKFLOW_STATUS_ORDERS.get(intervention.workflow_type, WORKFLOW_STATUS_ORDERS['corrective']), + rooms=Room.query.order_by(Room.name).all(), + categories=EquipmentCategory.query.order_by(EquipmentCategory.name).all(), + equipment_choices=Equipment.query.filter_by(is_deleted=False).order_by(Equipment.name).all(), services=Service.query.filter_by(is_active=True).order_by(Service.name).all(), companies=Company.query.filter_by(is_active=True).order_by(Company.name).all()) @@ -445,6 +448,34 @@ def save_work_details(id): return redirect(url_for('interventions.detail', id=id)) +@interventions_bp.route('//location', methods=['POST']) +@login_required +def update_location(id): + """Modifie la localisation en cascade salle -> catégorie -> équipement.""" + intervention = Intervention.query.get_or_404(id) + room_id = request.form.get('room_id', type=int) + category_id = request.form.get('category_id', type=int) + equipment_id = request.form.get('equipment_id', type=int) + room = Room.query.get(room_id) if room_id else None + category = EquipmentCategory.query.get(category_id) if category_id else None + equipment = Equipment.query.get(equipment_id) if equipment_id else None + if room_id and not room: + flash('Salle invalide.', 'danger') + return redirect(url_for('interventions.detail', id=id)) + if equipment: + if room_id and equipment.room_id != room_id: + flash("L'équipement choisi n'est pas dans la salle sélectionnée.", 'danger') + return redirect(url_for('interventions.detail', id=id)) + if category_id and equipment.effective_category_id != category_id: + flash("L'équipement choisi ne correspond pas à la catégorie sélectionnée.", 'danger') + return redirect(url_for('interventions.detail', id=id)) + intervention.room_id = room.id if room else None + intervention.equipment_id = equipment.id if equipment else None + db.session.commit() + flash('Salle et équipement concernés mis à jour.', 'success') + return redirect(url_for('interventions.detail', id=id)) + + @interventions_bp.route('//edit', methods=['GET', 'POST']) @login_required def edit(id): diff --git a/app_new/interventions/templates/detail.html b/app_new/interventions/templates/detail.html index 494e1f2..f4c32ea 100644 --- a/app_new/interventions/templates/detail.html +++ b/app_new/interventions/templates/detail.html @@ -286,10 +286,47 @@ {{ intervention.quantity_affected }} unité(s) concernée(s) {% endif %} - - {{ intervention.equipment.code or intervention.equipment.name }} - -
{{ intervention.equipment.full_path }} + {% if intervention.equipment %} + + {{ intervention.equipment.code or intervention.equipment.name }} + +
{{ intervention.equipment.full_path }} + {% else %} + Aucun équipement précis associé + {% endif %} + + + + +
+
+
Salle et équipement concernés
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
@@ -552,6 +589,29 @@ + +