feat: compute_frais_reels supporte la majoration +20% électrique

This commit is contained in:
2026-03-11 20:04:47 +01:00
parent d9ad854ede
commit 0362836a63
2 changed files with 30 additions and 11 deletions

View File

@@ -32,16 +32,19 @@ def compute_co2_grams(km_by_vehicle: dict[str, int], vehicles: dict) -> float:
return total
def compute_frais_reels(total_km_moteur: float, tranches: list[dict]) -> float:
def compute_frais_reels(total_km_moteur: float, tranches: list[dict], electric: bool = False) -> float:
"""
Calcule les frais réels fiscaux selon le barème kilométrique.
km_max = 0 signifie "pas de limite" (dernière tranche).
electric=True applique la majoration de 20 % pour véhicules électriques.
"""
if not tranches or total_km_moteur <= 0:
return 0.0
for tranche in tranches:
km_max = tranche["km_max"]
if km_max == 0 or total_km_moteur <= km_max:
return total_km_moteur * tranche["taux"] + tranche.get("forfait", 0)
result = total_km_moteur * tranche["taux"] + tranche.get("forfait", 0)
return result * 1.2 if electric else result
last = tranches[-1]
return total_km_moteur * last["taux"] + last.get("forfait", 0)
result = total_km_moteur * last["taux"] + last.get("forfait", 0)
return result * 1.2 if electric else result