# Generated by Django 5.2.12 on 2026-08-28 13:11

import django.db.models.deletion
import shortuuid.django_fields
import simple_history.models
import stock.models
from decimal import Decimal
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('Userauths', '0001_initial'),
        ('ecom', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='BaremeTimbre',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('montant_min', models.DecimalField(decimal_places=2, max_digits=12)),
                ('montant_max', models.DecimalField(blank=True, decimal_places=2, help_text='Laisser vide pour la tranche « et plus ».', max_digits=12, null=True)),
                ('montant_timbre', models.DecimalField(decimal_places=2, max_digits=10)),
                ('actif', models.BooleanField(default=True)),
                ('date_creation', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'verbose_name': 'Barème de timbre',
                'verbose_name_plural': 'Barèmes de timbres',
                'ordering': ['montant_min'],
            },
        ),
        migrations.CreateModel(
            name='Categorie',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('cid', shortuuid.django_fields.ShortUUIDField(alphabet='abcd1234', editable=False, length=6, max_length=6, prefix='', unique=True)),
                ('categorie', models.CharField(max_length=50, unique=True)),
                ('image', models.ImageField(blank=True, default='favicon.ico', null=True, upload_to='vehicules')),
                ('description', models.TextField(blank=True, max_length=2000, null=True)),
                ('actif', models.BooleanField(default=True)),
            ],
        ),
        migrations.CreateModel(
            name='Fournisseur',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('nom', models.CharField(max_length=255)),
                ('contact', models.CharField(blank=True, max_length=255)),
            ],
        ),
        migrations.CreateModel(
            name='MoyenPaiement',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('nom', models.CharField(max_length=100, unique=True)),
                ('code', models.CharField(max_length=100, unique=True)),
                ('actif', models.BooleanField(default=True)),
                ('date_creation', models.DateTimeField(auto_now_add=True)),
            ],
        ),
        migrations.CreateModel(
            name='ParametreTVA',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('libelle', models.CharField(blank=True, default='', help_text='Ex. TVA standard, TVA réduite…', max_length=100)),
                ('active', models.BooleanField(default=False, help_text='Si activé, la case TVA apparaît en caisse lors du paiement.')),
                ('taux', models.DecimalField(decimal_places=2, default=Decimal('18.00'), help_text='Taux de TVA en pourcentage (ex. 18 pour 18 %).', max_digits=5)),
                ('date_maj', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': 'Paramètre TVA',
                'verbose_name_plural': 'Paramètres TVA',
                'ordering': ['-active', 'taux', 'pk'],
            },
        ),
        migrations.CreateModel(
            name='Commande',
            fields=[
                ('id', models.CharField(default=stock.models.generate_numeric_id, editable=False, max_length=10, primary_key=True, serialize=False, unique=True)),
                ('numero_commande', models.CharField(max_length=100)),
                ('statut_commande', models.CharField(choices=[('en_attente', 'En attente'), ('valider', 'Validée'), ('annuler', 'Annulée'), ('livrer', 'Livrée')], default='en_attente', max_length=20)),
                ('total_sans_remise', models.DecimalField(decimal_places=2, max_digits=10)),
                ('total', models.DecimalField(decimal_places=2, max_digits=10)),
                ('date_creation', models.DateField(auto_now_add=True)),
                ('paye', models.BooleanField(default=False)),
                ('montant_paye', models.DecimalField(decimal_places=2, default=0.0, max_digits=10)),
                ('montant_reste', models.DecimalField(decimal_places=2, default=0.0, max_digits=10)),
                ('remise', models.DecimalField(decimal_places=2, default=0.0, max_digits=10)),
                ('profoma', models.PositiveIntegerField(default=0)),
                ('montant_timbre', models.DecimalField(decimal_places=2, default=Decimal('0.00'), help_text='Timbre fiscal (espèces). Non inclus dans le CA (total).', max_digits=10)),
                ('montant_tva', models.DecimalField(decimal_places=2, default=Decimal('0.00'), help_text='Montant TVA appliqué au paiement (optionnel).', max_digits=10)),
                ('tva_appliquee', models.BooleanField(default=False, help_text='Indique si la TVA a été cochée et appliquée au paiement.')),
                ('date', models.DateTimeField(auto_now_add=True, null=True)),
                ('commande_en_ligne', models.BooleanField(default=False)),
                ('client_confirme_reception', models.BooleanField(default=False)),
                ('date_reception_client', models.DateTimeField(blank=True, null=True)),
                ('bareme_timbre', models.ForeignKey(blank=True, help_text='Barème appliqué au moment du paiement.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='commandes', to='stock.baremetimbre')),
                ('livreur', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='commandes_livraison_online', to=settings.AUTH_USER_MODEL)),
                ('utilisateur', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='commandes_validees', to=settings.AUTH_USER_MODEL)),
                ('moyen_paiement', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='stock.moyenpaiement')),
            ],
        ),
        migrations.CreateModel(
            name='BonCommandePaiement',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('numero_bon', models.CharField(max_length=30, unique=True)),
                ('ticket_numero', models.CharField(max_length=100)),
                ('client_nom', models.CharField(blank=True, max_length=255)),
                ('moyen_paiement_nom', models.CharField(blank=True, max_length=100)),
                ('montant_paye', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('montant_reste', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('total_commande', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('fichier_pdf', models.FileField(blank=True, null=True, upload_to='bons_vente/')),
                ('date_emission', models.DateTimeField(auto_now_add=True)),
                ('caissier', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='bons_caisse_emis', to=settings.AUTH_USER_MODEL)),
                ('hote_accueil', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='bons_hote_accueil', to=settings.AUTH_USER_MODEL)),
                ('local_entrepot', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='bons_commande_paiement', to='Userauths.localentrepot')),
                ('commande', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='bon_paiement', to='stock.commande')),
            ],
            options={
                'verbose_name': 'Bon de commande (paiement)',
                'verbose_name_plural': 'Bons de commande (paiement)',
                'ordering': ['-date_emission'],
            },
        ),
        migrations.CreateModel(
            name='DemandeTransfert',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('numero_demande', models.CharField(max_length=30, unique=True)),
                ('motif', models.TextField(blank=True)),
                ('numero_bon_commande', models.CharField(blank=True, help_text='Numéro saisi par le demandeur à la réception (doit correspondre au bon donneur).', max_length=100)),
                ('numero_bon_donneur', models.CharField(blank=True, help_text="Numéro de bon saisi par le chef d'agence donneur à la validation.", max_length=100)),
                ('statut', models.CharField(choices=[('en_attente', 'En attente'), ('validee', 'Validée'), ('recue', 'Reçue'), ('annulee_demandeur', 'Annulée (demandeur)'), ('annulee_donneur', 'Annulée (donneur)')], default='en_attente', max_length=20)),
                ('date_demande', models.DateTimeField(auto_now_add=True)),
                ('date_validation', models.DateTimeField(blank=True, null=True)),
                ('date_reception', models.DateTimeField(blank=True, null=True)),
                ('demandeur', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='demandes_transfert_creees', to=settings.AUTH_USER_MODEL)),
                ('local_demandeur', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='demandes_transfert_emises', to='Userauths.localentrepot')),
                ('local_donneur', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='demandes_transfert_recues', to='Userauths.localentrepot')),
                ('receveur', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='demandes_transfert_recues_user', to=settings.AUTH_USER_MODEL)),
                ('validateur_donneur', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='demandes_transfert_validees', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-date_demande'],
            },
        ),
        migrations.CreateModel(
            name='GeniusPayPaiement',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('reference', models.CharField(db_index=True, max_length=64, unique=True)),
                ('source', models.CharField(choices=[('ecom', 'E-commerce'), ('caisse', 'Caisse')], max_length=16)),
                ('statut', models.CharField(choices=[('pending', 'En attente'), ('processing', 'En cours'), ('completed', 'Complété'), ('failed', 'Échoué'), ('cancelled', 'Annulé'), ('expired', 'Expiré')], default='pending', max_length=20)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('checkout_url', models.TextField(blank=True, default='')),
                ('payment_method', models.CharField(blank=True, default='', max_length=64)),
                ('environment', models.CharField(blank=True, default='', max_length=20)),
                ('appliquer_tva', models.BooleanField(default=False)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('raw_response', models.JSONField(blank=True, default=dict)),
                ('date_creation', models.DateTimeField(auto_now_add=True)),
                ('date_maj', models.DateTimeField(auto_now=True)),
                ('caissier', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='paiements_geniuspay_caisse', to=settings.AUTH_USER_MODEL)),
                ('commande', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='paiements_geniuspay', to='stock.commande')),
            ],
            options={
                'verbose_name': 'Paiement GeniusPay',
                'verbose_name_plural': 'Paiements GeniusPay',
                'ordering': ['-date_creation'],
            },
        ),
        migrations.CreateModel(
            name='HistoricalBaremeTimbre',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('montant_min', models.DecimalField(decimal_places=2, max_digits=12)),
                ('montant_max', models.DecimalField(blank=True, decimal_places=2, help_text='Laisser vide pour la tranche « et plus ».', max_digits=12, null=True)),
                ('montant_timbre', models.DecimalField(decimal_places=2, max_digits=10)),
                ('actif', models.BooleanField(default=True)),
                ('date_creation', models.DateTimeField(blank=True, editable=False)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'historical Barème de timbre',
                'verbose_name_plural': 'historical Barèmes de timbres',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalBonCommandePaiement',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('numero_bon', models.CharField(db_index=True, max_length=30)),
                ('ticket_numero', models.CharField(max_length=100)),
                ('client_nom', models.CharField(blank=True, max_length=255)),
                ('moyen_paiement_nom', models.CharField(blank=True, max_length=100)),
                ('montant_paye', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('montant_reste', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('total_commande', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('fichier_pdf', models.TextField(blank=True, max_length=100, null=True)),
                ('date_emission', models.DateTimeField(blank=True, editable=False)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('caissier', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('commande', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.commande')),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('hote_accueil', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('local_entrepot', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='Userauths.localentrepot')),
            ],
            options={
                'verbose_name': 'historical Bon de commande (paiement)',
                'verbose_name_plural': 'historical Bons de commande (paiement)',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalCategorie',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('cid', shortuuid.django_fields.ShortUUIDField(alphabet='abcd1234', db_index=True, editable=False, length=6, max_length=6, prefix='')),
                ('categorie', models.CharField(db_index=True, max_length=50)),
                ('image', models.TextField(blank=True, default='favicon.ico', max_length=100, null=True)),
                ('description', models.TextField(blank=True, max_length=2000, null=True)),
                ('actif', models.BooleanField(default=True)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'historical categorie',
                'verbose_name_plural': 'historical categories',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalDemandeTransfert',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('numero_demande', models.CharField(db_index=True, max_length=30)),
                ('motif', models.TextField(blank=True)),
                ('numero_bon_commande', models.CharField(blank=True, help_text='Numéro saisi par le demandeur à la réception (doit correspondre au bon donneur).', max_length=100)),
                ('numero_bon_donneur', models.CharField(blank=True, help_text="Numéro de bon saisi par le chef d'agence donneur à la validation.", max_length=100)),
                ('statut', models.CharField(choices=[('en_attente', 'En attente'), ('validee', 'Validée'), ('recue', 'Reçue'), ('annulee_demandeur', 'Annulée (demandeur)'), ('annulee_donneur', 'Annulée (donneur)')], default='en_attente', max_length=20)),
                ('date_demande', models.DateTimeField(blank=True, editable=False)),
                ('date_validation', models.DateTimeField(blank=True, null=True)),
                ('date_reception', models.DateTimeField(blank=True, null=True)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('demandeur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('local_demandeur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='Userauths.localentrepot')),
                ('local_donneur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='Userauths.localentrepot')),
                ('receveur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('validateur_donneur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'historical demande transfert',
                'verbose_name_plural': 'historical demande transferts',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalPanier',
            fields=[
                ('id', models.CharField(db_index=True, default=stock.models.generate_numeric_id, editable=False, max_length=10)),
                ('valide', models.BooleanField(default=False)),
                ('panier_paye', models.BooleanField(default=False)),
                ('date_creation', models.DateField(blank=True, editable=False)),
                ('ticket', models.CharField(blank=True, max_length=100, null=True)),
                ('panier_livre', models.BooleanField(default=False)),
                ('date_paie_panier', models.DateField(blank=True, null=True)),
                ('date_livr_panier', models.DateField(blank=True, null=True)),
                ('date_save', models.DateTimeField(blank=True, editable=False)),
                ('proforma', models.BooleanField(default=False)),
                ('nom_client', models.CharField(blank=True, max_length=255, null=True)),
                ('commande_en_ligne', models.BooleanField(default=False)),
                ('mode_reception', models.CharField(blank=True, choices=[('livraison', 'Livraison'), ('retrait', 'Retrait en magasin')], default='livraison', max_length=20)),
                ('adresse_domicile', models.CharField(blank=True, max_length=255, null=True)),
                ('telephone_livraison', models.CharField(blank=True, max_length=20, null=True)),
                ('frais_livraison', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=12)),
                ('instruction_livraison', models.TextField(blank=True, null=True)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('livraison_commune', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='ecom.communelivraison')),
                ('livraison_pays', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='ecom.payslivraison')),
                ('livraison_ville', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='ecom.villelivraison')),
                ('local_entrepot', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='Userauths.localentrepot')),
                ('utilisateur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'historical panier',
                'verbose_name_plural': 'historical paniers',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalParametreTVA',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('libelle', models.CharField(blank=True, default='', help_text='Ex. TVA standard, TVA réduite…', max_length=100)),
                ('active', models.BooleanField(default=False, help_text='Si activé, la case TVA apparaît en caisse lors du paiement.')),
                ('taux', models.DecimalField(decimal_places=2, default=Decimal('18.00'), help_text='Taux de TVA en pourcentage (ex. 18 pour 18 %).', max_digits=5)),
                ('date_maj', models.DateTimeField(blank=True, editable=False)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'historical Paramètre TVA',
                'verbose_name_plural': 'historical Paramètres TVA',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalSousCategorie',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('sid', shortuuid.django_fields.ShortUUIDField(alphabet='abcd1234', db_index=True, editable=False, length=6, max_length=6, prefix='')),
                ('nom', models.CharField(max_length=80)),
                ('slug', models.SlugField(blank=True, max_length=100)),
                ('image', models.TextField(blank=True, max_length=100, null=True)),
                ('description', models.TextField(blank=True, max_length=2000, null=True)),
                ('ordre', models.PositiveIntegerField(default=0)),
                ('actif', models.BooleanField(default=True)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('categorie', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.categorie')),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'historical Sous-catégorie',
                'verbose_name_plural': 'historical Sous-catégories',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalTarifLivraison',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('cout_par_km', models.DecimalField(decimal_places=2, help_text="Coût par défaut en FCFA / km (si aucun palier ne s'applique)", max_digits=10)),
                ('actif', models.BooleanField(default=True)),
                ('date_effet', models.DateTimeField(blank=True, editable=False)),
                ('date_fin', models.DateTimeField(blank=True, null=True)),
                ('motif', models.TextField(blank=True, help_text='Raison du changement de tarif')),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('cree_par', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'historical Tarif de livraison',
                'verbose_name_plural': 'historical Tarifs de livraison',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalTicket',
            fields=[
                ('id', models.CharField(db_index=True, default=stock.models.generate_numeric_id, editable=False, max_length=10)),
                ('numero', models.CharField(max_length=100)),
                ('date_creation', models.DateField(blank=True, editable=False)),
                ('utilise', models.BooleanField(default=False)),
                ('client_name', models.CharField(blank=True, max_length=25, null=True)),
                ('fichier_pdf', models.TextField(blank=True, max_length=100, null=True)),
                ('date_save', models.DateTimeField(blank=True, editable=False)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('commande', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.commande')),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('utilisateur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'historical ticket',
                'verbose_name_plural': 'historical tickets',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='Panier',
            fields=[
                ('id', models.CharField(default=stock.models.generate_numeric_id, editable=False, max_length=10, primary_key=True, serialize=False, unique=True)),
                ('valide', models.BooleanField(default=False)),
                ('panier_paye', models.BooleanField(default=False)),
                ('date_creation', models.DateField(auto_now_add=True)),
                ('ticket', models.CharField(blank=True, max_length=100, null=True)),
                ('panier_livre', models.BooleanField(default=False)),
                ('date_paie_panier', models.DateField(blank=True, null=True)),
                ('date_livr_panier', models.DateField(blank=True, null=True)),
                ('date_save', models.DateTimeField(auto_now_add=True)),
                ('proforma', models.BooleanField(default=False)),
                ('nom_client', models.CharField(blank=True, max_length=255, null=True)),
                ('commande_en_ligne', models.BooleanField(default=False)),
                ('mode_reception', models.CharField(blank=True, choices=[('livraison', 'Livraison'), ('retrait', 'Retrait en magasin')], default='livraison', max_length=20)),
                ('adresse_domicile', models.CharField(blank=True, max_length=255, null=True)),
                ('telephone_livraison', models.CharField(blank=True, max_length=20, null=True)),
                ('frais_livraison', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=12)),
                ('instruction_livraison', models.TextField(blank=True, null=True)),
                ('livraison_commune', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='paniers', to='ecom.communelivraison')),
                ('livraison_pays', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='paniers', to='ecom.payslivraison')),
                ('livraison_ville', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='paniers', to='ecom.villelivraison')),
                ('local_entrepot', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='paniers', to='Userauths.localentrepot')),
                ('utilisateur', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='paniers', to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='HistoricalCommande',
            fields=[
                ('id', models.CharField(db_index=True, default=stock.models.generate_numeric_id, editable=False, max_length=10)),
                ('numero_commande', models.CharField(max_length=100)),
                ('statut_commande', models.CharField(choices=[('en_attente', 'En attente'), ('valider', 'Validée'), ('annuler', 'Annulée'), ('livrer', 'Livrée')], default='en_attente', max_length=20)),
                ('total_sans_remise', models.DecimalField(decimal_places=2, max_digits=10)),
                ('total', models.DecimalField(decimal_places=2, max_digits=10)),
                ('date_creation', models.DateField(blank=True, editable=False)),
                ('paye', models.BooleanField(default=False)),
                ('montant_paye', models.DecimalField(decimal_places=2, default=0.0, max_digits=10)),
                ('montant_reste', models.DecimalField(decimal_places=2, default=0.0, max_digits=10)),
                ('remise', models.DecimalField(decimal_places=2, default=0.0, max_digits=10)),
                ('profoma', models.PositiveIntegerField(default=0)),
                ('montant_timbre', models.DecimalField(decimal_places=2, default=Decimal('0.00'), help_text='Timbre fiscal (espèces). Non inclus dans le CA (total).', max_digits=10)),
                ('montant_tva', models.DecimalField(decimal_places=2, default=Decimal('0.00'), help_text='Montant TVA appliqué au paiement (optionnel).', max_digits=10)),
                ('tva_appliquee', models.BooleanField(default=False, help_text='Indique si la TVA a été cochée et appliquée au paiement.')),
                ('date', models.DateTimeField(blank=True, editable=False, null=True)),
                ('commande_en_ligne', models.BooleanField(default=False)),
                ('client_confirme_reception', models.BooleanField(default=False)),
                ('date_reception_client', models.DateTimeField(blank=True, null=True)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('bareme_timbre', models.ForeignKey(blank=True, db_constraint=False, help_text='Barème appliqué au moment du paiement.', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.baremetimbre')),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('livreur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('utilisateur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('moyen_paiement', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.moyenpaiement')),
                ('panier', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.panier')),
            ],
            options={
                'verbose_name': 'historical commande',
                'verbose_name_plural': 'historical commandes',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.AddField(
            model_name='commande',
            name='panier',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='commands', to='stock.panier'),
        ),
        migrations.CreateModel(
            name='Piece',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('numero_piece', models.CharField(max_length=100, unique=True)),
                ('designation', models.CharField(max_length=255)),
                ('image', models.ImageField(blank=True, null=True, upload_to='pieces')),
                ('prix_achat', models.DecimalField(decimal_places=2, max_digits=10)),
                ('prix_unitaire', models.DecimalField(decimal_places=2, help_text='Prix catalogue / référence (gestionnaire). Les localités peuvent définir un prix sur StockLocal.', max_digits=10)),
                ('seuil', models.PositiveIntegerField(default=0, help_text='Seuil catalogue (défaut si seuil local non défini)')),
                ('emplacement', models.CharField(blank=True, default='', max_length=255)),
                ('date_creation', models.DateField(auto_now_add=True)),
                ('active_sortie', models.BooleanField(default=True, help_text='Archivage catalogue global (toutes localités).', null=True)),
                ('archive_le', models.DateTimeField(blank=True, null=True)),
                ('archive_motif', models.TextField(blank=True, default='', help_text="Motif de l'archivage catalogue.", max_length=500)),
                ('archive_par', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='pieces_archivees_catalogue', to=settings.AUTH_USER_MODEL)),
                ('categorie', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='stock.categorie')),
                ('utilisateur', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='PanierItem',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('new_price', models.DecimalField(decimal_places=2, default=0.0, max_digits=10)),
                ('quantite', models.PositiveIntegerField(default=1)),
                ('date_creation', models.DateField(auto_now_add=True)),
                ('panier', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='panier_items', to='stock.panier')),
                ('piece', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='stock.piece')),
            ],
        ),
        migrations.CreateModel(
            name='Notification',
            fields=[
                ('id', shortuuid.django_fields.ShortUUIDField(alphabet='abcd1234', editable=False, length=8, max_length=8, prefix='', primary_key=True, serialize=False, unique=True)),
                ('type_notification', models.CharField(choices=[('stock_alerte', 'Alerte de Stock'), ('transfert_demande', 'Demande de transfert'), ('commande_en_ligne', 'Commande en ligne'), ('chat_client', 'Chat client'), ('info', 'Information'), ('warning', 'Avertissement'), ('success', 'Succès')], default='stock_alerte', max_length=20)),
                ('titre', models.CharField(max_length=255)),
                ('message', models.TextField()),
                ('lu', models.BooleanField(default=False)),
                ('date_creation', models.DateTimeField(auto_now_add=True)),
                ('creneau', models.CharField(blank=True, db_index=True, max_length=32, null=True)),
                ('utilisateur', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='notifications', to=settings.AUTH_USER_MODEL)),
                ('pieces_alerte', models.ManyToManyField(blank=True, related_name='notifications_alerte', to='stock.piece')),
            ],
            options={
                'verbose_name': 'Notification',
                'verbose_name_plural': 'Notifications',
                'ordering': ['-date_creation'],
            },
        ),
        migrations.CreateModel(
            name='LigneDemandeTransfert',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantite', models.PositiveIntegerField()),
                ('demande', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lignes', to='stock.demandetransfert')),
                ('piece', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='lignes_demande_transfert', to='stock.piece')),
            ],
        ),
        migrations.CreateModel(
            name='HistoricalTransfertStock',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('numero', models.CharField(db_index=True, max_length=30)),
                ('quantite', models.PositiveIntegerField()),
                ('statut', models.CharField(choices=[('en_attente', 'En attente'), ('en_transit', 'En transit'), ('recu', 'Reçu'), ('annule', 'Annulé')], default='en_attente', max_length=15)),
                ('motif', models.TextField(blank=True)),
                ('date_demande', models.DateTimeField(blank=True, editable=False)),
                ('date_envoi', models.DateTimeField(blank=True, null=True)),
                ('date_reception', models.DateTimeField(blank=True, null=True)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('demandeur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('local_destination', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='Userauths.localentrepot')),
                ('local_source', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='Userauths.localentrepot')),
                ('receveur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('piece', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.piece')),
            ],
            options={
                'verbose_name': 'historical transfert stock',
                'verbose_name_plural': 'historical transfert stocks',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalStockLocal',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('quantite_disponible', models.PositiveIntegerField(default=0)),
                ('seuil_local', models.PositiveIntegerField(default=0)),
                ('prix_unitaire_local', models.DecimalField(blank=True, decimal_places=2, help_text='Prix de vente fixé par la localité. Si vide, utilise le prix catalogue.', max_digits=10, null=True)),
                ('emplacement', models.CharField(blank=True, default='', max_length=255)),
                ('active_sortie', models.BooleanField(default=True, help_text='Si False, la pièce est masquée à la vente dans cette localité uniquement.')),
                ('archive_le', models.DateTimeField(blank=True, null=True)),
                ('archive_motif', models.TextField(blank=True, default='', help_text="Motif de l'archivage dans cette localité.", max_length=500)),
                ('date_maj', models.DateTimeField(blank=True, editable=False)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('archive_par', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('local_entrepot', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='Userauths.localentrepot')),
                ('piece', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.piece')),
            ],
            options={
                'verbose_name': 'historical Stock local',
                'verbose_name_plural': 'historical Stocks par localité',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalPanierItem',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('new_price', models.DecimalField(decimal_places=2, default=0.0, max_digits=10)),
                ('quantite', models.PositiveIntegerField(default=1)),
                ('date_creation', models.DateField(blank=True, editable=False)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('panier', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.panier')),
                ('piece', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.piece')),
            ],
            options={
                'verbose_name': 'historical panier item',
                'verbose_name_plural': 'historical panier items',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalLigneDemandeTransfert',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('quantite', models.PositiveIntegerField()),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('demande', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.demandetransfert')),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('piece', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.piece')),
            ],
            options={
                'verbose_name': 'historical ligne demande transfert',
                'verbose_name_plural': 'historical ligne demande transferts',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalEntrePiece',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('quantitajout', models.PositiveIntegerField(default=0)),
                ('prix_achat', models.DecimalField(decimal_places=2, max_digits=10)),
                ('date_creation', models.DateField(blank=True, editable=False)),
                ('origine_type', models.CharField(choices=[('fournisseur', 'Fournisseur'), ('transfert_local', 'Transfert inter-localité')], default='fournisseur', max_length=20)),
                ('date', models.DateTimeField(blank=True, editable=False)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('demande_transfert', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.demandetransfert')),
                ('fournisseur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.fournisseur')),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('local_entrepot', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='Userauths.localentrepot')),
                ('origine_local', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='Userauths.localentrepot')),
                ('utilisateur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('piece', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.piece')),
            ],
            options={
                'verbose_name': 'historical entre piece',
                'verbose_name_plural': 'historical entre pieces',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='EntrePiece',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantitajout', models.PositiveIntegerField(default=0)),
                ('prix_achat', models.DecimalField(decimal_places=2, max_digits=10)),
                ('date_creation', models.DateField(auto_now_add=True)),
                ('origine_type', models.CharField(choices=[('fournisseur', 'Fournisseur'), ('transfert_local', 'Transfert inter-localité')], default='fournisseur', max_length=20)),
                ('date', models.DateTimeField(auto_now_add=True)),
                ('demande_transfert', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='entrees_stock', to='stock.demandetransfert')),
                ('local_entrepot', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='entrees_stock', to='Userauths.localentrepot')),
                ('origine_local', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='entrees_provenance_transfert', to='Userauths.localentrepot')),
                ('utilisateur', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('fournisseur', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='stock.fournisseur')),
                ('piece', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='stock.piece')),
            ],
        ),
        migrations.CreateModel(
            name='PieceImage',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('image', models.ImageField(upload_to='pieces/galerie')),
                ('ordre', models.PositiveSmallIntegerField(default=0)),
                ('legende', models.CharField(blank=True, default='', max_length=255)),
                ('date_creation', models.DateTimeField(auto_now_add=True)),
                ('piece', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='images_supplementaires', to='stock.piece')),
            ],
            options={
                'verbose_name': 'Image supplémentaire',
                'verbose_name_plural': 'Images supplémentaires',
                'ordering': ['ordre', 'pk'],
            },
        ),
        migrations.CreateModel(
            name='SousCategorie',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('sid', shortuuid.django_fields.ShortUUIDField(alphabet='abcd1234', editable=False, length=6, max_length=6, prefix='', unique=True)),
                ('nom', models.CharField(max_length=80)),
                ('slug', models.SlugField(blank=True, max_length=100)),
                ('image', models.ImageField(blank=True, null=True, upload_to='sous_categories')),
                ('description', models.TextField(blank=True, max_length=2000, null=True)),
                ('ordre', models.PositiveIntegerField(default=0)),
                ('actif', models.BooleanField(default=True)),
                ('categorie', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sous_categories', to='stock.categorie')),
            ],
            options={
                'verbose_name': 'Sous-catégorie',
                'verbose_name_plural': 'Sous-catégories',
                'ordering': ['ordre', 'nom'],
            },
        ),
        migrations.AddField(
            model_name='piece',
            name='sous_categorie',
            field=models.ForeignKey(blank=True, help_text='Sous-catégorie optionnelle, rattachée à la catégorie.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='pieces', to='stock.souscategorie'),
        ),
        migrations.CreateModel(
            name='HistoricalPiece',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('numero_piece', models.CharField(db_index=True, max_length=100)),
                ('designation', models.CharField(max_length=255)),
                ('image', models.TextField(blank=True, max_length=100, null=True)),
                ('prix_achat', models.DecimalField(decimal_places=2, max_digits=10)),
                ('prix_unitaire', models.DecimalField(decimal_places=2, help_text='Prix catalogue / référence (gestionnaire). Les localités peuvent définir un prix sur StockLocal.', max_digits=10)),
                ('seuil', models.PositiveIntegerField(default=0, help_text='Seuil catalogue (défaut si seuil local non défini)')),
                ('emplacement', models.CharField(blank=True, default='', max_length=255)),
                ('date_creation', models.DateField(blank=True, editable=False)),
                ('active_sortie', models.BooleanField(default=True, help_text='Archivage catalogue global (toutes localités).', null=True)),
                ('archive_le', models.DateTimeField(blank=True, null=True)),
                ('archive_motif', models.TextField(blank=True, default='', help_text="Motif de l'archivage catalogue.", max_length=500)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('archive_par', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('categorie', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.categorie')),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('utilisateur', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('sous_categorie', models.ForeignKey(blank=True, db_constraint=False, help_text='Sous-catégorie optionnelle, rattachée à la catégorie.', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.souscategorie')),
            ],
            options={
                'verbose_name': 'historical piece',
                'verbose_name_plural': 'historical pieces',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='StockLocal',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantite_disponible', models.PositiveIntegerField(default=0)),
                ('seuil_local', models.PositiveIntegerField(default=0)),
                ('prix_unitaire_local', models.DecimalField(blank=True, decimal_places=2, help_text='Prix de vente fixé par la localité. Si vide, utilise le prix catalogue.', max_digits=10, null=True)),
                ('emplacement', models.CharField(blank=True, default='', max_length=255)),
                ('active_sortie', models.BooleanField(default=True, help_text='Si False, la pièce est masquée à la vente dans cette localité uniquement.')),
                ('archive_le', models.DateTimeField(blank=True, null=True)),
                ('archive_motif', models.TextField(blank=True, default='', help_text="Motif de l'archivage dans cette localité.", max_length=500)),
                ('date_maj', models.DateTimeField(auto_now=True)),
                ('archive_par', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='stocks_archives', to=settings.AUTH_USER_MODEL)),
                ('local_entrepot', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='stocks', to='Userauths.localentrepot')),
                ('piece', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='stocks', to='stock.piece')),
            ],
            options={
                'verbose_name': 'Stock local',
                'verbose_name_plural': 'Stocks par localité',
            },
        ),
        migrations.CreateModel(
            name='TarifLivraison',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('cout_par_km', models.DecimalField(decimal_places=2, help_text="Coût par défaut en FCFA / km (si aucun palier ne s'applique)", max_digits=10)),
                ('actif', models.BooleanField(default=True)),
                ('date_effet', models.DateTimeField(auto_now_add=True)),
                ('date_fin', models.DateTimeField(blank=True, null=True)),
                ('motif', models.TextField(blank=True, help_text='Raison du changement de tarif')),
                ('cree_par', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='tarifs_livraison_crees', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Tarif de livraison',
                'verbose_name_plural': 'Tarifs de livraison',
                'ordering': ['-date_effet'],
            },
        ),
        migrations.CreateModel(
            name='PalierLivraison',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('km_min', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=8)),
                ('km_max', models.DecimalField(blank=True, decimal_places=2, help_text='Laisser vide pour « et plus »', max_digits=8, null=True)),
                ('cout_par_km', models.DecimalField(decimal_places=2, help_text='Tarif FCFA/km pour cet intervalle', max_digits=10)),
                ('ordre', models.PositiveIntegerField(default=0)),
                ('tarif', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='paliers', to='stock.tariflivraison')),
            ],
            options={
                'verbose_name': 'Palier de livraison',
                'verbose_name_plural': 'Paliers de livraison',
                'ordering': ['ordre', 'km_min'],
            },
        ),
        migrations.CreateModel(
            name='HistoricalBonLivraison',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('numero_bon_livraison', models.CharField(db_index=True, max_length=30)),
                ('distance_km', models.DecimalField(decimal_places=2, help_text='Distance estimée entre les deux localités', max_digits=8)),
                ('cout_base', models.DecimalField(decimal_places=2, help_text='Coût calculé automatiquement (figé à la création)', max_digits=12)),
                ('cout_ajustement', models.DecimalField(decimal_places=2, default=Decimal('0.00'), help_text='Ajustement manuel (+ surcharge, − remise)', max_digits=12)),
                ('motif_ajustement', models.TextField(blank=True)),
                ('statut', models.CharField(choices=[('en_preparation', 'En attente'), ('en_route', 'En route'), ('livre', 'Livré'), ('annule', 'Annulé')], default='en_preparation', max_length=20)),
                ('date_creation', models.DateTimeField(blank=True, editable=False)),
                ('date_depart', models.DateTimeField(blank=True, null=True)),
                ('date_livraison_effective', models.DateTimeField(blank=True, null=True)),
                ('observations', models.TextField(blank=True)),
                ('fichier_pdf', models.TextField(blank=True, max_length=100, null=True)),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
                ('cree_par', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('demande_transfert', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.demandetransfert')),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('livreur', models.ForeignKey(blank=True, db_constraint=False, help_text='Livreur de la localité donneuse', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('tarif_applique', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='stock.tariflivraison')),
            ],
            options={
                'verbose_name': 'historical Bon de livraison',
                'verbose_name_plural': 'historical Bons de livraison',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='BonLivraison',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('numero_bon_livraison', models.CharField(max_length=30, unique=True)),
                ('distance_km', models.DecimalField(decimal_places=2, help_text='Distance estimée entre les deux localités', max_digits=8)),
                ('cout_base', models.DecimalField(decimal_places=2, help_text='Coût calculé automatiquement (figé à la création)', max_digits=12)),
                ('cout_ajustement', models.DecimalField(decimal_places=2, default=Decimal('0.00'), help_text='Ajustement manuel (+ surcharge, − remise)', max_digits=12)),
                ('motif_ajustement', models.TextField(blank=True)),
                ('statut', models.CharField(choices=[('en_preparation', 'En attente'), ('en_route', 'En route'), ('livre', 'Livré'), ('annule', 'Annulé')], default='en_preparation', max_length=20)),
                ('date_creation', models.DateTimeField(auto_now_add=True)),
                ('date_depart', models.DateTimeField(blank=True, null=True)),
                ('date_livraison_effective', models.DateTimeField(blank=True, null=True)),
                ('observations', models.TextField(blank=True)),
                ('fichier_pdf', models.FileField(blank=True, null=True, upload_to='bons_livraison/')),
                ('cree_par', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='bons_livraison_crees', to=settings.AUTH_USER_MODEL)),
                ('livreur', models.ForeignKey(help_text='Livreur de la localité donneuse', on_delete=django.db.models.deletion.PROTECT, related_name='livraisons_transferts', to=settings.AUTH_USER_MODEL)),
                ('demande_transfert', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='bon_livraison', to='stock.demandetransfert')),
                ('tarif_applique', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='bons_livraison', to='stock.tariflivraison')),
            ],
            options={
                'verbose_name': 'Bon de livraison',
                'verbose_name_plural': 'Bons de livraison',
                'ordering': ['-date_creation'],
            },
        ),
        migrations.CreateModel(
            name='Ticket',
            fields=[
                ('id', models.CharField(default=stock.models.generate_numeric_id, editable=False, max_length=10, primary_key=True, serialize=False, unique=True)),
                ('numero', models.CharField(max_length=100)),
                ('date_creation', models.DateField(auto_now_add=True)),
                ('utilise', models.BooleanField(default=False)),
                ('client_name', models.CharField(blank=True, max_length=25, null=True)),
                ('fichier_pdf', models.FileField(blank=True, null=True, upload_to='tickets/')),
                ('date_save', models.DateTimeField(auto_now_add=True)),
                ('commande', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='stock.commande')),
                ('utilisateur', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='livraisons_effectuees', to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='TransfertStock',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('numero', models.CharField(max_length=30, unique=True)),
                ('quantite', models.PositiveIntegerField()),
                ('statut', models.CharField(choices=[('en_attente', 'En attente'), ('en_transit', 'En transit'), ('recu', 'Reçu'), ('annule', 'Annulé')], default='en_attente', max_length=15)),
                ('motif', models.TextField(blank=True)),
                ('date_demande', models.DateTimeField(auto_now_add=True)),
                ('date_envoi', models.DateTimeField(blank=True, null=True)),
                ('date_reception', models.DateTimeField(blank=True, null=True)),
                ('demandeur', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='transferts_demandes', to=settings.AUTH_USER_MODEL)),
                ('local_destination', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='transferts_entrants', to='Userauths.localentrepot')),
                ('local_source', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='transferts_sortants', to='Userauths.localentrepot')),
                ('piece', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='transferts', to='stock.piece')),
                ('receveur', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='transferts_recus', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-date_demande'],
            },
        ),
        migrations.AddConstraint(
            model_name='demandetransfert',
            constraint=models.CheckConstraint(condition=models.Q(('local_demandeur', models.F('local_donneur')), _negated=True), name='demande_transfert_demandeur_diff_donneur'),
        ),
        migrations.AddConstraint(
            model_name='lignedemandetransfert',
            constraint=models.UniqueConstraint(fields=('demande', 'piece'), name='demande_transfert_ligne_piece_unique'),
        ),
        migrations.AddConstraint(
            model_name='souscategorie',
            constraint=models.UniqueConstraint(fields=('categorie', 'nom'), name='souscategorie_categorie_nom_unique'),
        ),
        migrations.AddIndex(
            model_name='stocklocal',
            index=models.Index(fields=['piece', 'local_entrepot'], name='stock_stock_piece_i_87bb66_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='stocklocal',
            unique_together={('piece', 'local_entrepot')},
        ),
        migrations.AddConstraint(
            model_name='transfertstock',
            constraint=models.CheckConstraint(condition=models.Q(('local_source', models.F('local_destination')), _negated=True), name='transfert_source_diff_destination'),
        ),
    ]
