# Generated by Django 6.0.6 on 2026-10-13 17:01

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('organizations', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='FinanceAccount',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=120)),
                ('type', models.CharField(choices=[('cash', 'cash'), ('bank', 'bank')], default='bank', max_length=10)),
                ('opening_balance', models.BigIntegerField(default=0)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='finance_accounts', to='organizations.organization')),
            ],
            options={
                'ordering': ['id'],
            },
        ),
        migrations.CreateModel(
            name='FinanceCategory',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=120)),
                ('kind', models.CharField(choices=[('income', 'income'), ('expense', 'expense')], max_length=10)),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='finance_categories', to='organizations.organization')),
            ],
            options={
                'ordering': ['kind', 'name'],
            },
        ),
        migrations.CreateModel(
            name='Transaction',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('kind', models.CharField(choices=[('income', 'income'), ('expense', 'expense')], max_length=10)),
                ('amount', models.BigIntegerField()),
                ('date', models.DateField()),
                ('description', models.CharField(blank=True, default='', max_length=300)),
                ('source_type', models.CharField(choices=[('manual', 'manual'), ('invoice', 'invoice'), ('payroll', 'payroll')], default='manual', max_length=10)),
                ('source_id', models.PositiveIntegerField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('account', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='transactions', to='finance.financeaccount')),
                ('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='transactions', to='finance.financecategory')),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='finance_transactions', to='organizations.organization')),
            ],
            options={
                'ordering': ['-date', '-id'],
            },
        ),
        migrations.AddConstraint(
            model_name='financeaccount',
            constraint=models.UniqueConstraint(fields=('organization', 'name'), name='unique_finance_account_name'),
        ),
        migrations.AddConstraint(
            model_name='financecategory',
            constraint=models.UniqueConstraint(fields=('organization', 'name', 'kind'), name='unique_finance_category'),
        ),
        migrations.AddIndex(
            model_name='transaction',
            index=models.Index(fields=['organization', 'date'], name='finance_tra_organiz_9cc92a_idx'),
        ),
        migrations.AddConstraint(
            model_name='transaction',
            constraint=models.UniqueConstraint(condition=models.Q(('source_type', 'manual'), _negated=True), fields=('organization', 'source_type', 'source_id'), name='unique_finance_source'),
        ),
    ]
