Corriger les totaux et replier la vue zones
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run

This commit is contained in:
root 2026-08-17 00:29:42 +00:00
parent 49a8d5839d
commit c978be2e70
2 changed files with 7 additions and 7 deletions

View file

@ -149,17 +149,17 @@ def hierarchy(id):
root = Equipment.query.get_or_404(id)
descendants = select(
Equipment.id, Equipment.parent_id, Equipment.name, Equipment.code,
Equipment.status, Equipment.room_id,
Equipment.status, Equipment.room_id, Equipment.quantity,
Equipment.room_id.label('effective_room_id'),
).where(Equipment.parent_id == root.id, Equipment.is_deleted.is_(False)).cte(recursive=True)
descendants = descendants.union_all(select(
Equipment.id, Equipment.parent_id, Equipment.name, Equipment.code,
Equipment.status, Equipment.room_id,
Equipment.status, Equipment.room_id, Equipment.quantity,
db.func.coalesce(Equipment.room_id, descendants.c.effective_room_id).label('effective_room_id'),
).where(Equipment.parent_id == descendants.c.id, Equipment.is_deleted.is_(False)))
rows = db.session.execute(
select(descendants.c.id, descendants.c.name, descendants.c.code,
descendants.c.status, Room.id.label('room_id'), Room.name.label('room_name'),
descendants.c.status, descendants.c.quantity, Room.id.label('room_id'), Room.name.label('room_name'),
Zone.id.label('zone_id'), Zone.name.label('zone_name'))
.select_from(descendants)
.join(Room, descendants.c.effective_room_id == Room.id, isouter=True)
@ -174,7 +174,7 @@ def hierarchy(id):
room = zone['rooms'].setdefault(room_key, {'name': row.room_name or 'Sans salle', 'items': []})
room['items'].append({
'id': row.id, 'name': row.name, 'code': row.code,
'status': row.status,
'status': row.status, 'quantity': row.quantity or 1,
'status_label': format_status(row.status),
'status_class': f"bg-{status_badge_class(row.status)}",
'url': url_for('equipments.detail', id=row.id),
@ -182,7 +182,7 @@ def hierarchy(id):
payload = []
for zone in zones.values():
rooms = list(zone['rooms'].values())
payload.append({'name': zone['name'], 'count': sum(len(room['items']) for room in rooms), 'rooms': rooms})
payload.append({'name': zone['name'], 'count': sum(item['quantity'] for room in rooms for item in room['items']), 'rooms': rooms})
return jsonify({'root_id': root.id, 'zones': payload})

View file

@ -61,7 +61,7 @@
{% if view == 'zones' %}
<div class="alert alert-info py-2"><i class="bi bi-info-circle"></i> Quantités regroupées par zone, salle et type déquipement.</div>
{% for building in zone_tree %}<div class="card mb-3 border-0 shadow-sm"><div class="card-header fw-semibold"><i class="bi bi-building"></i> {{ building.name }}</div><div class="card-body">
{% for zone in building.zones %}<details class="mb-2" open><summary class="fw-semibold"><i class="bi bi-signpost-split"></i> {{ zone.name }} <span class="badge bg-light text-dark">{{ zone.rooms|length }} salle(s)</span></summary>{% for room in zone.rooms %}<details class="border rounded p-2 mb-2 ms-3" open><summary><a href="{{ url_for('rooms.detail', id=room.id) }}" class="text-decoration-none"><i class="bi bi-door-open"></i> {{ room.name }}</a> <span class="badge bg-primary">{{ room.types|sum(attribute='quantity') }}</span></summary><table class="table table-sm mb-0 mt-1"><tbody>{% for item in room.types %}<tr><td><a href="{{ url_for('equipments.detail', id=item.ids[0]) }}" class="text-decoration-none">{{ item.name }}</a></td><td class="text-muted">{{ item.category }}</td><td class="text-end"><span class="badge bg-primary">{{ item.quantity }}</span></td></tr>{% endfor %}</tbody></table></details>{% endfor %}</details>{% endfor %}</div></div>{% else %}<div class="text-muted text-center py-4">Aucun équipement localisé.</div>{% endfor %}
{% for zone in building.zones %}<details class="mb-2"><summary class="fw-semibold"><i class="bi bi-signpost-split"></i> {{ zone.name }} <span class="badge bg-light text-dark">{{ zone.rooms|length }} salle(s)</span></summary>{% for room in zone.rooms %}<details class="border rounded p-2 mb-2 ms-3"><summary><a href="{{ url_for('rooms.detail', id=room.id) }}" class="text-decoration-none"><i class="bi bi-door-open"></i> {{ room.name }}</a> <span class="badge bg-primary">{{ room.types|sum(attribute='quantity') }}</span></summary><table class="table table-sm mb-0 mt-1"><tbody>{% for item in room.types %}<tr><td><a href="{{ url_for('equipments.detail', id=item.ids[0]) }}" class="text-decoration-none">{{ item.name }}</a></td><td class="text-muted">{{ item.category }}</td><td class="text-end"><span class="badge bg-primary">{{ item.quantity }}</span></td></tr>{% endfor %}</tbody></table></details>{% endfor %}</details>{% endfor %}</div></div>{% else %}<div class="text-muted text-center py-4">Aucun équipement localisé.</div>{% endfor %}
{% else %}
{% if parents %}
<div class="accordion" id="parentsAccordion">
@ -231,7 +231,7 @@ function renderHierarchy(target, zones) {
details.className = 'ms-2 mb-2';
const summary = document.createElement('summary');
summary.className = 'fw-semibold';
summary.textContent = `${room.name} (${room.items.length})`;
summary.textContent = `${room.name} (${room.items.reduce((total, item) => total + (item.quantity || 1), 0)})`;
details.appendChild(summary);
const list = document.createElement('div');
list.className = 'list-group list-group-flush ms-3 mt-1';