# Generated by Django 5.2.14 on 2026-08-26 21:43

import django.db.models.deletion
import simple_history.models
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('orders', '0002_historicalorder_order_number_order_order_number'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='HistoricalInvoice',
            fields=[
                ('id', models.IntegerField(blank=True, db_index=True)),
                ('is_deleted', models.BooleanField(default=False, verbose_name='Eliminado')),
                ('created_at', models.DateField(blank=True, editable=False, verbose_name='Fecha de Creación')),
                ('updated_at', models.DateField(blank=True, editable=False, verbose_name='Fecha de Modificación')),
                ('deleted_at', models.DateField(blank=True, null=True, verbose_name='Fecha de Eliminación')),
                ('invoice_number', models.CharField(db_index=True, help_text='Formato FAC-nnnn-año (ej. FAC-0001-2026)', max_length=50, verbose_name='Número de Factura')),
                ('customer_name', models.CharField(max_length=255, verbose_name='Nombre o Razón Social')),
                ('customer_tax_id', models.CharField(max_length=50, verbose_name='DNI / RIF / NIT / RUT')),
                ('customer_email', models.EmailField(max_length=254, verbose_name='Correo Electrónico')),
                ('billing_address', models.TextField(verbose_name='Dirección de Facturación')),
                ('subtotal', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='Subtotal')),
                ('discount_amount', models.DecimalField(decimal_places=2, default=0.0, max_digits=10, verbose_name='Descuento Aplicado')),
                ('total', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='Total Facturado')),
                ('items_snapshot', models.JSONField(help_text='Lista con nombre, cantidad y precio unitario de los productos facturados.')),
                ('pdf_file', models.TextField(blank=True, max_length=100, null=True, verbose_name='Factura en PDF')),
                ('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)),
                ('order', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='orders.order', verbose_name='Orden')),
            ],
            options={
                'verbose_name': 'historical Factura',
                'verbose_name_plural': 'historical Facturas',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='Invoice',
            fields=[
                ('id', models.AutoField(primary_key=True, serialize=False)),
                ('is_deleted', models.BooleanField(default=False, verbose_name='Eliminado')),
                ('created_at', models.DateField(auto_now_add=True, verbose_name='Fecha de Creación')),
                ('updated_at', models.DateField(auto_now=True, verbose_name='Fecha de Modificación')),
                ('deleted_at', models.DateField(blank=True, null=True, verbose_name='Fecha de Eliminación')),
                ('invoice_number', models.CharField(help_text='Formato FAC-nnnn-año (ej. FAC-0001-2026)', max_length=50, unique=True, verbose_name='Número de Factura')),
                ('customer_name', models.CharField(max_length=255, verbose_name='Nombre o Razón Social')),
                ('customer_tax_id', models.CharField(max_length=50, verbose_name='DNI / RIF / NIT / RUT')),
                ('customer_email', models.EmailField(max_length=254, verbose_name='Correo Electrónico')),
                ('billing_address', models.TextField(verbose_name='Dirección de Facturación')),
                ('subtotal', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='Subtotal')),
                ('discount_amount', models.DecimalField(decimal_places=2, default=0.0, max_digits=10, verbose_name='Descuento Aplicado')),
                ('total', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='Total Facturado')),
                ('items_snapshot', models.JSONField(help_text='Lista con nombre, cantidad y precio unitario de los productos facturados.')),
                ('pdf_file', models.FileField(blank=True, null=True, upload_to='invoices_pdf/', verbose_name='Factura en PDF')),
                ('order', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='invoice', to='orders.order', verbose_name='Orden')),
            ],
            options={
                'verbose_name': 'Factura',
                'verbose_name_plural': 'Facturas',
                'ordering': ['-created_at'],
            },
        ),
    ]
