Groupe Gestionnaire + import CSV des operations
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,12 +1,13 @@
|
||||
"""
|
||||
Charge les DONNÉES DE RÉFÉRENCE (barèmes + catégories) — sans données de démo.
|
||||
Idempotent : sûr à relancer en production après chaque mise à jour.
|
||||
Données de RÉFÉRENCE (barèmes + catégories + groupe Gestionnaire) — sans démo.
|
||||
Idempotent : sûr à relancer en production. Appelé par l'entrypoint au démarrage.
|
||||
|
||||
Usage : python manage.py seed_reference
|
||||
"""
|
||||
from decimal import Decimal
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth.models import Group, Permission
|
||||
|
||||
from compta.models import Bareme, Categorie, Activite
|
||||
|
||||
@@ -19,7 +20,6 @@ BAREMES_2026 = [
|
||||
Decimal("83600"), Decimal("37500"), Decimal("41250")),
|
||||
]
|
||||
|
||||
# exclure_calculs=True => mouvement neutre (hors calculs fiscaux).
|
||||
CATEGORIES = [
|
||||
("Vente de produits finis", "vente", False, 1),
|
||||
("Prestation de services", "vente", False, 2),
|
||||
@@ -35,6 +35,30 @@ CATEGORIES = [
|
||||
("Virement interne", "neutre", True, 5),
|
||||
]
|
||||
|
||||
# Permissions du groupe "Gestionnaire entreprise"
|
||||
GROUPE_NOM = "Gestionnaire entreprise"
|
||||
PERMS_COMPLETES = ["client", "facture", "lignefacture", "depense", "paiement"] # add/change/delete/view
|
||||
PERMS_CHANGE = ["entreprise"] # view + change (pas add/delete, ni gestion des accès)
|
||||
PERMS_VUE = ["categorie", "bareme"] # view seulement
|
||||
|
||||
|
||||
def charger_groupes():
|
||||
g, _ = Group.objects.get_or_create(name=GROUPE_NOM)
|
||||
perms = []
|
||||
for model in PERMS_COMPLETES:
|
||||
for action in ("add", "change", "delete", "view"):
|
||||
perms += list(Permission.objects.filter(
|
||||
content_type__app_label="compta", codename=f"{action}_{model}"))
|
||||
for model in PERMS_CHANGE:
|
||||
for action in ("view", "change"):
|
||||
perms += list(Permission.objects.filter(
|
||||
content_type__app_label="compta", codename=f"{action}_{model}"))
|
||||
for model in PERMS_VUE:
|
||||
perms += list(Permission.objects.filter(
|
||||
content_type__app_label="compta", codename=f"view_{model}"))
|
||||
g.permissions.set(perms)
|
||||
return g
|
||||
|
||||
|
||||
def charger_reference(stdout=None, style=None):
|
||||
for act, urssaf, ab, vl, sca, tb, tm in BAREMES_2026:
|
||||
@@ -47,14 +71,16 @@ def charger_reference(stdout=None, style=None):
|
||||
c, _ = Categorie.objects.update_or_create(
|
||||
nom=nom, defaults=dict(usage=usage, exclure_calculs=excl, ordre=ordre))
|
||||
cat[nom] = c
|
||||
g = charger_groupes()
|
||||
if stdout and style:
|
||||
stdout.write(style.SUCCESS(
|
||||
f"Référence chargée : {len(BAREMES_2026)} barèmes, {len(cat)} catégories."))
|
||||
f"Référence : {len(BAREMES_2026)} barèmes, {len(cat)} catégories, "
|
||||
f"groupe « {g.name} » ({g.permissions.count()} permissions)."))
|
||||
return cat
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Charge les barèmes et catégories de référence (sans démo)."
|
||||
help = "Charge barèmes, catégories et le groupe Gestionnaire (sans démo)."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
charger_reference(self.stdout, self.style)
|
||||
|
||||
Reference in New Issue
Block a user