# Generated by Django 5.2.4 on 2026-09-07 06:31 from decimal import Decimal import django.core.validators import django.db.models.deletion from django.conf import settings from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ ("commerce", "0012_sale_customer_external_id_sale_customer_name"), ("finance", "0031_payrolltablereviewmark"), migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( name="ReportingEntry", fields=[ ( "id", models.BigAutoField( auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), ( "kind", models.CharField( choices=[ ("production", "Выпуск продукции"), ("purchase", "Закупка для производства"), ("tax", "Уплаченные налоги сотрудника"), ("overhead", "Общие расходы"), ("cash_in", "Поступление денег"), ("cash_out", "Выплата денег"), ], max_length=16, ), ), ("date", models.DateField(db_index=True, verbose_name="Дата факта")), ( "reference", models.CharField( max_length=200, verbose_name="Документ / уникальный номер" ), ), ( "description", models.CharField( blank=True, max_length=500, verbose_name="Описание" ), ), ( "quantity", models.DecimalField( decimal_places=4, default=0, max_digits=18, validators=[ django.core.validators.MinValueValidator(Decimal("0")) ], ), ), ( "amount", models.DecimalField( decimal_places=2, default=0, max_digits=18, validators=[ django.core.validators.MinValueValidator(Decimal("0")) ], ), ), ( "currency", models.CharField( default="RUB", max_length=3, validators=[ django.core.validators.RegexValidator("^[A-Z]{3}$") ], ), ), ("created_at", models.DateTimeField(auto_now_add=True)), ("voided_at", models.DateTimeField(blank=True, null=True)), ( "created_by", models.ForeignKey( on_delete=django.db.models.deletion.PROTECT, related_name="reporting_entries_created", to=settings.AUTH_USER_MODEL, ), ), ( "employee", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, ), ), ( "product", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to="commerce.product", ), ), ( "voided_by", models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name="reporting_entries_voided", to=settings.AUTH_USER_MODEL, ), ), ], options={ "ordering": ["-date", "-pk"], "constraints": [ models.UniqueConstraint( fields=("kind", "reference"), name="reporting_entry_reference_unique", ), models.CheckConstraint( condition=models.Q(("amount__gte", 0), ("quantity__gte", 0)), name="reporting_entry_nonnegative", ), models.CheckConstraint( condition=models.Q( models.Q( ("amount", 0), ("employee__isnull", True), ("kind", "production"), ("product__isnull", False), ("quantity__gt", 0), ), models.Q( ("amount__gt", 0), ("employee__isnull", True), ("kind", "purchase"), ), models.Q( ("amount__gt", 0), ("employee__isnull", False), ("kind", "tax"), ("product__isnull", True), ("quantity", 0), ), models.Q( ("amount__gt", 0), ("employee__isnull", True), ("kind__in", ["overhead", "cash_in", "cash_out"]), ("product__isnull", True), ("quantity", 0), ), _connector="OR", ), name="reporting_entry_kind_fields", ), ], }, ), ]