# Generated by Django 4.2.2 on 2023-09-09 13:34

from decimal import Decimal
import django.core.serializers.json
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

    dependencies = [
        ('django_ledger', '0007_remove_customermodel_django_ledg_custome_16f95a_idx_and_more'),
    ]

    operations = [
        migrations.CreateModel(
            name='ClosingEntryModel',
            fields=[
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True, null=True)),
                ('markdown_notes', models.TextField(blank=True, null=True, verbose_name='Markdown Notes')),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('closing_date', models.DateField(verbose_name='Closing Date')),
                ('posted', models.BooleanField(default=False, verbose_name='Is Posted')),
            ],
            options={
                'ordering': ['-closing_date'],
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='ClosingEntryTransactionModel',
            fields=[
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True, null=True)),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('activity', models.CharField(blank=True, choices=[('Operating', (('op', 'Operating'),)), ('Investing', (('inv_ppe', 'Purchase/Disposition of PPE'), ('inv_securities', 'Purchase/Disposition of Securities'), ('inv', 'Investing Activity Other'))), ('Financing', (('fin_std', 'Payoff of Short Term Debt'), ('fin_ltd', 'Payoff of Long Term Debt'), ('fin_equity', 'Issuance of Common Stock, Preferred Stock or Capital Contribution'), ('fin_dividends', 'Dividends or Distributions to Shareholders'), ('fin', 'Financing Activity Other')))], max_length=20, null=True, verbose_name='Activity')),
                ('tx_type', models.CharField(choices=[('credit', 'Credit'), ('debit', 'Debit')], max_length=10, verbose_name='Transaction Type')),
                ('balance', models.DecimalField(decimal_places=6, max_digits=20, validators=[django.core.validators.MinValueValidator(limit_value=Decimal('0.00'))], verbose_name='Closing Entry Balance')),
            ],
            options={
                'verbose_name': 'Closing Entry Model',
                'ordering': ['-created'],
                'abstract': False,
            },
        ),
        migrations.AddField(
            model_name='entitymodel',
            name='last_closing_date',
            field=models.DateField(blank=True, null=True, verbose_name='Last Closing Entry Date'),
        ),
        migrations.AddField(
            model_name='entitymodel',
            name='meta',
            field=models.JSONField(blank=True, default=dict, null=True),
        ),
        migrations.AddField(
            model_name='journalentrymodel',
            name='is_closing_entry',
            field=models.BooleanField(default=False),
        ),
        migrations.AddField(
            model_name='ledgermodel',
            name='additional_info',
            field=models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder, null=True),
        ),
        migrations.AlterField(
            model_name='transactionmodel',
            name='journal_entry',
            field=models.ForeignKey(editable=False, help_text='Journal Entry to be associated with this transaction.', on_delete=django.db.models.deletion.CASCADE, to='django_ledger.journalentrymodel', verbose_name='Journal Entry'),
        ),
        migrations.AddIndex(
            model_name='journalentrymodel',
            index=models.Index(fields=['is_closing_entry'], name='django_ledg_is_clos_0ef09e_idx'),
        ),
        migrations.AddField(
            model_name='closingentrytransactionmodel',
            name='account_model',
            field=models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='django_ledger.accountmodel', verbose_name='Account Model'),
        ),
        migrations.AddField(
            model_name='closingentrytransactionmodel',
            name='closing_entry_model',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='django_ledger.closingentrymodel'),
        ),
        migrations.AddField(
            model_name='closingentrytransactionmodel',
            name='unit_model',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.RESTRICT, to='django_ledger.entityunitmodel', verbose_name='Entity Model'),
        ),
        migrations.AddField(
            model_name='closingentrymodel',
            name='entity_model',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='django_ledger.entitymodel', verbose_name='Entity Model'),
        ),
        migrations.AddField(
            model_name='closingentrymodel',
            name='ledger_model',
            field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='django_ledger.ledgermodel'),
        ),
        migrations.AddIndex(
            model_name='closingentrytransactionmodel',
            index=models.Index(fields=['closing_entry_model'], name='django_ledg_closing_a7a576_idx'),
        ),
        migrations.AddIndex(
            model_name='closingentrytransactionmodel',
            index=models.Index(fields=['account_model'], name='django_ledg_account_5d90df_idx'),
        ),
        migrations.AddConstraint(
            model_name='closingentrytransactionmodel',
            constraint=models.UniqueConstraint(fields=('closing_entry_model', 'account_model', 'unit_model', 'activity'), name='unique_closing_entry'),
        ),
        migrations.AddConstraint(
            model_name='closingentrytransactionmodel',
            constraint=models.UniqueConstraint(condition=models.Q(('activity', None)), fields=('closing_entry_model', 'account_model', 'unit_model'), name='unique_ce_opt_1'),
        ),
        migrations.AddConstraint(
            model_name='closingentrytransactionmodel',
            constraint=models.UniqueConstraint(condition=models.Q(('unit_model', None)), fields=('closing_entry_model', 'account_model', 'activity'), name='unique_ce_opt_2'),
        ),
        migrations.AddConstraint(
            model_name='closingentrytransactionmodel',
            constraint=models.UniqueConstraint(condition=models.Q(('unit_model', None), ('activity', None)), fields=('closing_entry_model', 'account_model'), name='unique_ce_opt_3'),
        ),
        migrations.AddIndex(
            model_name='closingentrymodel',
            index=models.Index(fields=['entity_model'], name='django_ledg_entity__4a55a2_idx'),
        ),
        migrations.AddIndex(
            model_name='closingentrymodel',
            index=models.Index(fields=['closing_date'], name='django_ledg_closing_28e3bb_idx'),
        ),
        migrations.AddIndex(
            model_name='closingentrymodel',
            index=models.Index(fields=['posted'], name='django_ledg_posted_8db18b_idx'),
        ),
        migrations.AddIndex(
            model_name='closingentrymodel',
            index=models.Index(fields=['entity_model', 'posted', 'closing_date'], name='django_ledg_entity__9ee361_idx'),
        ),
        migrations.AddConstraint(
            model_name='closingentrymodel',
            constraint=models.UniqueConstraint(fields=('entity_model', 'closing_date'), name='unique_entity_closing_date', violation_error_message='Only one Closing Entry for Date Allowed.'),
        ),
    ]
