﻿# Generated by Django 6.0.1 on 2026-04-08 20:18

"""Migration Django de creation initiale de l'application proforma."""

import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models

# Migration de creation initiale du module proforma :
# elle introduit les tables entete, lignes et paiements necessaires aux
# documents commerciaux prepares avant fiscalisation definitive.


class Migration(migrations.Migration):
    """Cree les tables principales necessaires au cycle commercial proforma."""

    initial = True

    dependencies = [
        ('facturation', '0022_alter_commande_type_facture_proforma'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Proforma',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('numero', models.CharField(db_index=True, editable=False, max_length=50, unique=True)),
                ('montant_total', models.DecimalField(decimal_places=2, default=0, max_digits=12)),
                ('montant_paye', models.DecimalField(decimal_places=2, default=0, max_digits=12)),
                ('remise_globale', models.DecimalField(decimal_places=2, default=0, max_digits=12)),
                ('tva_montant', models.DecimalField(decimal_places=2, default=0, max_digits=12)),
                ('statut_paiement', models.CharField(choices=[('PAYEE', 'Payee'), ('PARTIELLE', 'Partiellement payee'), ('IMPAYEE', 'Impayee')], default='IMPAYEE', max_length=20)),
                ('taux_change_applique', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)),
                ('mode_dgi', models.CharField(default='ttc', max_length=5)),
                ('commentaire', models.TextField(blank=True, null=True)),
                ('date_proforma', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('client', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='proformas', to='facturation.client')),
                ('point_de_vente', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='proformas', to='facturation.pointdevente')),
                ('vendeur', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='proformas_creees', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Pro-Forma',
                'verbose_name_plural': 'Pro-Formas',
                'ordering': ['-date_proforma'],
            },
        ),
        migrations.CreateModel(
            name='ProformaItem',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('designation', models.CharField(max_length=255)),
                ('code_sku', models.CharField(blank=True, max_length=50)),
                ('unite_mesure', models.CharField(blank=True, max_length=50)),
                ('quantite', models.DecimalField(decimal_places=3, max_digits=10)),
                ('prix_unitaire', models.DecimalField(decimal_places=2, max_digits=12)),
                ('remise', models.DecimalField(decimal_places=2, default=0, max_digits=12)),
                ('sous_total', models.DecimalField(decimal_places=2, max_digits=12)),
                ('tax_group_code', models.CharField(blank=True, max_length=10)),
                ('tax_rate', models.DecimalField(decimal_places=2, default=0, max_digits=5)),
                ('est_taxe_specifique', models.BooleanField(default=False)),
                ('taxe_specifique_valeur', models.CharField(blank=True, max_length=50)),
                ('taxe_specifique_description', models.CharField(blank=True, max_length=100)),
                ('produit', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='lignes_proforma', to='facturation.produit')),
                ('proforma', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lignes', to='proforma.proforma')),
            ],
            options={
                'verbose_name': 'Ligne de Pro-Forma',
                'verbose_name_plural': 'Lignes de Pro-Forma',
                'ordering': ['id'],
            },
        ),
        migrations.CreateModel(
            name='ProformaPayment',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('montant', models.DecimalField(decimal_places=2, help_text='Montant converti en devise systeme (CDF)', max_digits=12)),
                ('montant_verse', models.DecimalField(decimal_places=2, default=0, max_digits=12)),
                ('devise', models.CharField(choices=[('USD', 'Dollar Americain'), ('CDF', 'Franc Congolais')], default='CDF', max_length=3)),
                ('taux_transaction', models.DecimalField(decimal_places=2, default=1, max_digits=10)),
                ('date_paiement', models.DateTimeField(default=django.utils.timezone.now)),
                ('reference_transaction', models.CharField(blank=True, max_length=100, null=True)),
                ('mode_paiement', models.ForeignKey(db_column='mode_paiement', on_delete=django.db.models.deletion.PROTECT, to='facturation.modepaiement')),
                ('proforma', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='paiements', to='proforma.proforma')),
            ],
            options={
                'verbose_name': 'Paiement de Pro-Forma',
                'verbose_name_plural': 'Paiements de Pro-Forma',
                'ordering': ['date_paiement', 'id'],
            },
        ),
    ]
