# Generated by Django 5.0.10 on 2026-01-14 07:04

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('accounts', '0001_initial'),
        ('customers', '0002_initial'),
        ('inventory', '0002_initial'),
        ('orders', '0001_initial'),
        ('products', '0001_initial'),
    ]

    operations = [
        migrations.AddField(
            model_name='kititemsnapshot',
            name='original_product',
            field=models.ForeignKey(blank=True, help_text='Ссылка на товар для резервирования на складе', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='kit_item_snapshots', to='products.product', verbose_name='Оригинальный товар'),
        ),
        migrations.AddField(
            model_name='kitsnapshot',
            name='original_kit',
            field=models.ForeignKey(blank=True, help_text='Ссылка на комплект, с которого создан снимок', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='snapshots', to='products.productkit', verbose_name='Оригинальный комплект'),
        ),
        migrations.AddField(
            model_name='kititemsnapshot',
            name='kit_snapshot',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='orders.kitsnapshot', verbose_name='Снимок комплекта'),
        ),
        migrations.AddField(
            model_name='order',
            name='customer',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='orders', to='customers.customer', verbose_name='Клиент'),
        ),
        migrations.AddField(
            model_name='order',
            name='modified_by',
            field=models.ForeignKey(blank=True, help_text='Последний пользователь, изменивший заказ', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='modified_orders', to='accounts.customuser', verbose_name='Изменен пользователем'),
        ),
        migrations.AddField(
            model_name='delivery',
            name='order',
            field=models.OneToOneField(help_text='Заказ, к которому относится доставка', on_delete=django.db.models.deletion.CASCADE, related_name='delivery', to='orders.order', verbose_name='Заказ'),
        ),
        migrations.AddField(
            model_name='orderitem',
            name='kit_snapshot',
            field=models.ForeignKey(blank=True, help_text='Хранит состав комплекта на момент оформления заказа', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='order_items', to='orders.kitsnapshot', verbose_name='Снимок комплекта'),
        ),
        migrations.AddField(
            model_name='orderitem',
            name='order',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='orders.order', verbose_name='Заказ'),
        ),
        migrations.AddField(
            model_name='orderitem',
            name='product',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='order_items', to='products.product', verbose_name='Товар'),
        ),
        migrations.AddField(
            model_name='orderitem',
            name='product_kit',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='order_items', to='products.productkit', verbose_name='Комплект товаров'),
        ),
        migrations.AddField(
            model_name='orderitem',
            name='sales_unit',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='order_items', to='products.productsalesunit', verbose_name='Единица продажи'),
        ),
        migrations.AddField(
            model_name='orderitem',
            name='showcase',
            field=models.ForeignKey(blank=True, help_text='Витрина, с которой был продан товар', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='order_items', to='inventory.showcase', verbose_name='Витрина'),
        ),
        migrations.AddField(
            model_name='orderstatus',
            name='created_by',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_order_statuses', to='accounts.customuser', verbose_name='Создано'),
        ),
        migrations.AddField(
            model_name='orderstatus',
            name='updated_by',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated_order_statuses', to='accounts.customuser', verbose_name='Последнее изменение'),
        ),
        migrations.AddField(
            model_name='order',
            name='status',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='orders', to='orders.orderstatus', verbose_name='Статус заказа'),
        ),
        migrations.AddField(
            model_name='paymentmethod',
            name='created_by',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_payment_methods', to='accounts.customuser', verbose_name='Создано'),
        ),
        migrations.AddIndex(
            model_name='recipient',
            index=models.Index(fields=['phone'], name='orders_reci_phone_735356_idx'),
        ),
        migrations.AddIndex(
            model_name='recipient',
            index=models.Index(fields=['name'], name='orders_reci_name_e52d5b_idx'),
        ),
        migrations.AddIndex(
            model_name='recipient',
            index=models.Index(fields=['created_at'], name='orders_reci_created_34a391_idx'),
        ),
        migrations.AddField(
            model_name='order',
            name='recipient',
            field=models.ForeignKey(blank=True, help_text='Заполняется, если покупатель не является получателем', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to='orders.recipient', verbose_name='Получатель'),
        ),
        migrations.AddField(
            model_name='transaction',
            name='created_by',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='transactions_created', to='accounts.customuser', verbose_name='Создал'),
        ),
        migrations.AddField(
            model_name='transaction',
            name='order',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='transactions', to='orders.order', verbose_name='Заказ'),
        ),
        migrations.AddField(
            model_name='transaction',
            name='payment_method',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='transactions', to='orders.paymentmethod', verbose_name='Способ оплаты/возврата'),
        ),
        migrations.AddField(
            model_name='transaction',
            name='related_payment',
            field=models.ForeignKey(blank=True, help_text='Для возвратов - на какой платёж ссылается этот возврат', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='refunds', to='orders.transaction', verbose_name='Связанный платёж'),
        ),
        migrations.AddIndex(
            model_name='kitsnapshot',
            index=models.Index(fields=['original_kit'], name='orders_kits_origina_f8d311_idx'),
        ),
        migrations.AddIndex(
            model_name='kitsnapshot',
            index=models.Index(fields=['created_at'], name='orders_kits_created_70de88_idx'),
        ),
        migrations.AddIndex(
            model_name='kititemsnapshot',
            index=models.Index(fields=['kit_snapshot'], name='orders_kiti_kit_sna_bf307e_idx'),
        ),
        migrations.AddIndex(
            model_name='delivery',
            index=models.Index(fields=['delivery_type'], name='orders_deli_deliver_ac3dc8_idx'),
        ),
        migrations.AddIndex(
            model_name='delivery',
            index=models.Index(fields=['created_at'], name='orders_deli_created_1a3ff3_idx'),
        ),
        migrations.AddIndex(
            model_name='delivery',
            index=models.Index(fields=['delivery_date'], name='orders_deli_deliver_e898e4_idx'),
        ),
        migrations.AddIndex(
            model_name='delivery',
            index=models.Index(fields=['time_from'], name='orders_deli_time_fr_916f57_idx'),
        ),
        migrations.AddIndex(
            model_name='delivery',
            index=models.Index(fields=['time_to'], name='orders_deli_time_to_7f2573_idx'),
        ),
        migrations.AddIndex(
            model_name='orderitem',
            index=models.Index(fields=['order'], name='orders_orde_order_i_5d347b_idx'),
        ),
        migrations.AddIndex(
            model_name='orderitem',
            index=models.Index(fields=['product'], name='orders_orde_product_32ff41_idx'),
        ),
        migrations.AddIndex(
            model_name='orderitem',
            index=models.Index(fields=['product_kit'], name='orders_orde_product_925b51_idx'),
        ),
        migrations.AddIndex(
            model_name='orderitem',
            index=models.Index(fields=['is_from_showcase'], name='orders_orde_is_from_32d8f7_idx'),
        ),
        migrations.AddIndex(
            model_name='orderitem',
            index=models.Index(fields=['showcase'], name='orders_orde_showcas_aa97bd_idx'),
        ),
        migrations.AddIndex(
            model_name='orderstatus',
            index=models.Index(fields=['code'], name='orders_orde_code_5e1ef7_idx'),
        ),
        migrations.AddIndex(
            model_name='orderstatus',
            index=models.Index(fields=['is_system'], name='orders_orde_is_syst_2f5b85_idx'),
        ),
        migrations.AddIndex(
            model_name='orderstatus',
            index=models.Index(fields=['order'], name='orders_orde_order_2e2930_idx'),
        ),
        migrations.AddConstraint(
            model_name='orderstatus',
            constraint=models.CheckConstraint(check=models.Q(('is_positive_end', True), ('is_negative_end', True), _negated=True), name='not_both_positive_and_negative_end', violation_error_message='Статус не может быть одновременно положительным и отрицательным концом'),
        ),
        migrations.AddIndex(
            model_name='paymentmethod',
            index=models.Index(fields=['code'], name='orders_paym_code_f40d7e_idx'),
        ),
        migrations.AddIndex(
            model_name='paymentmethod',
            index=models.Index(fields=['is_active'], name='orders_paym_is_acti_e2be69_idx'),
        ),
        migrations.AddIndex(
            model_name='paymentmethod',
            index=models.Index(fields=['order'], name='orders_paym_order_94e282_idx'),
        ),
        migrations.AddIndex(
            model_name='order',
            index=models.Index(fields=['customer'], name='orders_orde_custome_59b6fb_idx'),
        ),
        migrations.AddIndex(
            model_name='order',
            index=models.Index(fields=['status'], name='orders_orde_status__eb4f00_idx'),
        ),
        migrations.AddIndex(
            model_name='order',
            index=models.Index(fields=['payment_status'], name='orders_orde_payment_bc131d_idx'),
        ),
        migrations.AddIndex(
            model_name='order',
            index=models.Index(fields=['created_at'], name='orders_orde_created_0e92de_idx'),
        ),
        migrations.AddIndex(
            model_name='order',
            index=models.Index(fields=['order_number'], name='orders_orde_order_n_f3ada5_idx'),
        ),
        migrations.AddIndex(
            model_name='transaction',
            index=models.Index(fields=['order', '-transaction_date'], name='orders_tran_order_i_dc90ee_idx'),
        ),
        migrations.AddIndex(
            model_name='transaction',
            index=models.Index(fields=['transaction_type'], name='orders_tran_transac_3d971d_idx'),
        ),
        migrations.AddIndex(
            model_name='transaction',
            index=models.Index(fields=['payment_method'], name='orders_tran_payment_7e354c_idx'),
        ),
        migrations.AddIndex(
            model_name='transaction',
            index=models.Index(fields=['transaction_date'], name='orders_tran_transac_1bae48_idx'),
        ),
    ]
