Catégories globales + flag neutre + seed_reference

This commit is contained in:
2026-06-30 00:43:18 +02:00
parent 0398e45f2f
commit 54f9fc56f4
29 changed files with 210 additions and 56 deletions
+7 -4
View File
@@ -8,7 +8,7 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from .models import Entreprise, Paiement, Depense, Activite, RegimeTva
from .models import Entreprise, Paiement, Depense, Activite, RegimeTva, Categorie
def _dec(val, defaut="0"):
@@ -41,10 +41,10 @@ def saisie_paiement(request):
m = _dec(montants[i] if i < len(montants) else "0")
lib = (libelles[i] or "").strip()
if m == 0 and not lib:
continue # ligne vide ignorée
continue
lignes.append({
"libelle": lib or "(sans libellé)",
"categorie": categories[i] if i < len(categories) else "",
"categorie_id": categories[i] if i < len(categories) else "",
"activite": activites[i] if i < len(activites) else "",
"regime": regimes[i] if i < len(regimes) else RegimeTva.NATIONALE,
"taux": _dec(taux[i] if i < len(taux) else "0"),
@@ -71,13 +71,14 @@ def saisie_paiement(request):
return render(request, "compta/saisie_paiement.html",
_context(entreprises, request.POST))
cats = {str(c.pk): c for c in Categorie.objects.all()}
paiement = Paiement.objects.create(
entreprise=entreprise, date=d, libelle=libelle,
montant_total=montant_total, sens="debit")
for l in lignes:
Depense.objects.create(
entreprise=entreprise, paiement=paiement, date=d,
libelle=l["libelle"], categorie=l["categorie"],
libelle=l["libelle"], categorie=cats.get(l["categorie_id"]),
activite=l["activite"] or "", regime_tva=l["regime"],
taux_tva=l["taux"], montant_ttc=l["montant"], montant_tva=l["tva"])
@@ -94,6 +95,8 @@ def _context(entreprises, post=None):
"entreprises": entreprises,
"activites": Activite.choices,
"regimes": RegimeTva.choices,
"categories": Categorie.objects.filter(
actif=True).exclude(usage="vente"),
"today": date.today().isoformat(),
"post": post,
}