Checkpoint: Ajout de mode_ventilation dans buildLignesFromSource (copié depuis p.mode_ventilation du JSON). Enrichissement de loadOpexState pour fusionner mode_ventilation depuis la source JSON sur les lignes déjà sauvegardées dans localStorage (rétrocompatibilité). La colonne Ventilation affiche maintenant les vraies valeurs du fichier Excel source.

This commit is contained in:
Manus
2026-06-10 09:36:47 +00:00
parent c762998f69
commit 772dff3061

View File

@@ -166,6 +166,7 @@ function buildLignesFromSource(annee?: number): LigneOpex[] {
budget_n1: p.budget_n1 ?? 0, budget_n1: p.budget_n1 ?? 0,
montant: (annee === 2025 ? p.montant_previsionnel_2025 : p.montant_previsionnel_2026) ?? 0, montant: (annee === 2025 ? p.montant_previsionnel_2025 : p.montant_previsionnel_2026) ?? 0,
isCustom: false, isCustom: false,
mode_ventilation: p.mode_ventilation ?? null,
})); }));
} }
@@ -192,13 +193,20 @@ function loadOpexState(annee: number): OpexAnneeState {
if (parsed.lignes && Array.isArray(parsed.lignes)) { if (parsed.lignes && Array.isArray(parsed.lignes)) {
// Filtrer les lignes parasites (libellés = noms de catégories ou de synthèse) // Filtrer les lignes parasites (libellés = noms de catégories ou de synthèse)
const lignesFiltrees = parsed.lignes.filter(l => !isLigneParasite(l)); const lignesFiltrees = parsed.lignes.filter(l => !isLigneParasite(l));
if (lignesFiltrees.length !== parsed.lignes.length) { // Enrichir avec mode_ventilation depuis la source JSON (les anciennes sauvegardes ne l'ont pas)
// Purger et sauvegarder la version nettoyée const srcLignes = (annee === 2025 || annee === 2026) ? buildLignesFromSource(annee) : [];
const cleaned = { ...parsed, lignes: lignesFiltrees }; const srcMap = new Map(srcLignes.map(l => [l.libelle, l]));
const lignesEnrichies = lignesFiltrees.map(l => ({
...l,
mode_ventilation: l.mode_ventilation ?? srcMap.get(l.libelle)?.mode_ventilation ?? null,
}));
const needsSave = lignesFiltrees.length !== parsed.lignes.length || lignesEnrichies.some((l, i) => l.mode_ventilation !== lignesFiltrees[i]?.mode_ventilation);
if (needsSave) {
const cleaned = { ...parsed, lignes: lignesEnrichies };
try { localStorage.setItem(getOpexStorageKey(annee), JSON.stringify(cleaned)); } catch { /* ignore */ } try { localStorage.setItem(getOpexStorageKey(annee), JSON.stringify(cleaned)); } catch { /* ignore */ }
return cleaned; return cleaned;
} }
return parsed; return { ...parsed, lignes: lignesEnrichies };
} }
} }
} catch { /* ignore */ } } catch { /* ignore */ }