87 lines
4.3 KiB
Python
87 lines
4.3 KiB
Python
"""
|
|
Charge les données de RÉFÉRENCE (barèmes + catégories) puis un jeu de
|
|
données d'EXEMPLE (entreprise, clients, factures, dépenses).
|
|
Pour la prod, préférez `seed_reference` (référence seule, sans démo).
|
|
|
|
Usage : python manage.py seed_demo
|
|
"""
|
|
from decimal import Decimal
|
|
from datetime import date
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from compta.models import (
|
|
Entreprise, Client, Facture, LigneFacture, Depense, Activite,
|
|
StatutFacture, RegimeTva,
|
|
)
|
|
from compta.management.commands.seed_reference import charger_reference
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Charge la référence + des données d'exemple."
|
|
|
|
def handle(self, *args, **options):
|
|
cat = charger_reference(self.stdout, self.style)
|
|
|
|
ent, _ = Entreprise.objects.get_or_create(
|
|
nom="JB Conseil",
|
|
defaults=dict(activite=Activite.SERVICE_BIC, franchise_tva=False,
|
|
taux_tva_defaut=Decimal("20.00"),
|
|
versement_liberatoire=True, email="jb@example.fr",
|
|
num_tva_intracom="FR00123456789"))
|
|
|
|
clients = {}
|
|
for nom, mail in [("Acme SARL", "contact@acme.fr"),
|
|
("Studio Lumiere", "hello@studiolumiere.fr"),
|
|
("Mairie de Ville", "compta@ville.fr")]:
|
|
c, _ = Client.objects.get_or_create(entreprise=ent, nom=nom,
|
|
defaults=dict(email=mail))
|
|
clients[nom] = c
|
|
|
|
V, S = Activite.VENTE, Activite.SERVICE_BIC
|
|
factures = [
|
|
("2026-001", "Acme SARL", S, date(2026, 1, 10), date(2026, 1, 25),
|
|
StatutFacture.ENCAISSEE, [("Dépannage informatique", 2, 600)]),
|
|
("2026-002", "Studio Lumiere", V, date(2026, 1, 18), date(2026, 2, 5),
|
|
StatutFacture.ENCAISSEE, [("Impression 3D - lot pièces", 1, 800)]),
|
|
("2026-003", "Mairie de Ville", S, date(2026, 2, 2), date(2026, 2, 20),
|
|
StatutFacture.ENCAISSEE, [("Maintenance parc", 1, 2500)]),
|
|
("2026-004", "Acme SARL", V, date(2026, 3, 1), date(2026, 3, 15),
|
|
StatutFacture.ENCAISSEE, [("Impression 3D - prototype", 1, 1500)]),
|
|
("2026-005", "Studio Lumiere", S, date(2026, 3, 20), None,
|
|
StatutFacture.ENVOYEE, [("Audit poste de travail", 1, 950)]),
|
|
]
|
|
for numero, client_nom, activite, emis, enc, statut, lignes in factures:
|
|
f, created = Facture.objects.get_or_create(
|
|
entreprise=ent, numero=numero,
|
|
defaults=dict(client=clients[client_nom], activite=activite,
|
|
date_emission=emis, date_encaissement=enc,
|
|
statut=statut))
|
|
if created:
|
|
for des, qte, pu in lignes:
|
|
LigneFacture.objects.create(
|
|
facture=f, designation=des, quantite=Decimal(qte),
|
|
prix_unitaire_ht=Decimal(pu), taux_tva=Decimal("20"))
|
|
f.recompute_totaux()
|
|
|
|
Depense.objects.get_or_create(
|
|
entreprise=ent, libelle="Bobines PLA/PETG", date=date(2026, 1, 15),
|
|
defaults=dict(categorie=cat["Matière première"], activite=Activite.VENTE,
|
|
montant_ttc=Decimal("96.00"), montant_tva=Decimal("16.00")))
|
|
Depense.objects.get_or_create(
|
|
entreprise=ent, libelle="Abonnement outils", date=date(2026, 2, 10),
|
|
defaults=dict(categorie=cat["Abonnement logiciel"],
|
|
activite=Activite.SERVICE_BIC,
|
|
montant_ttc=Decimal("34.80"), montant_tva=Decimal("5.80")))
|
|
Depense.objects.get_or_create(
|
|
entreprise=ent, libelle="Imprimante 3D (DE)", date=date(2026, 2, 20),
|
|
defaults=dict(categorie=cat["Matériel et outillage"], activite=Activite.VENTE,
|
|
regime_tva=RegimeTva.INTRACOM, taux_tva=Decimal("20"),
|
|
montant_ttc=Decimal("500.00"), montant_tva=Decimal("0")))
|
|
Depense.objects.get_or_create(
|
|
entreprise=ent, libelle="URSSAF DE LORRAINE", date=date(2026, 3, 3),
|
|
defaults=dict(categorie=cat["Cotisation sociale Urssaf"],
|
|
montant_ttc=Decimal("73.00"), montant_tva=Decimal("0")))
|
|
|
|
self.stdout.write(self.style.SUCCESS("Données d'exemple chargées."))
|