# Generated by Django 6.0.6 on 2026-10-13 16:45

import django.db.models.deletion
from decimal import Decimal
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('crm', '0002_alter_interaction_options_interaction_occurred_time'),
        ('organizations', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Invoice',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('number', models.PositiveIntegerField(blank=True, null=True)),
                ('status', models.CharField(choices=[('draft', 'draft'), ('issued', 'issued'), ('paid', 'paid'), ('cancelled', 'cancelled')], default='draft', max_length=10)),
                ('issue_date', models.DateField()),
                ('due_date', models.DateField(blank=True, null=True)),
                ('notes', models.TextField(blank=True, default='')),
                ('tax_percent', models.DecimalField(decimal_places=2, default=Decimal('10'), max_digits=5)),
                ('discount', models.BigIntegerField(default=0)),
                ('subtotal', models.BigIntegerField(default=0)),
                ('tax', models.BigIntegerField(default=0)),
                ('total', models.BigIntegerField(default=0)),
                ('issued_at', models.DateTimeField(blank=True, null=True)),
                ('paid_at', models.DateTimeField(blank=True, null=True)),
                ('cancelled_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='invoices', to='crm.customer')),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='invoices', to='organizations.organization')),
            ],
            options={
                'ordering': ['-created_at', '-id'],
            },
        ),
        migrations.CreateModel(
            name='InvoiceItem',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('description', models.CharField(max_length=300)),
                ('quantity', models.DecimalField(decimal_places=3, default=Decimal('1'), max_digits=12)),
                ('unit_price', models.BigIntegerField(default=0)),
                ('line_total', models.BigIntegerField(default=0)),
                ('invoice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='invoicing.invoice')),
            ],
            options={
                'ordering': ['id'],
            },
        ),
        migrations.AddConstraint(
            model_name='invoice',
            constraint=models.UniqueConstraint(condition=models.Q(('number__isnull', False)), fields=('organization', 'number'), name='unique_invoice_number_per_org'),
        ),
    ]
