# Generated by Django 5.2.7 on 2025-11-06 05:33

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('basic_info', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='PurchaseOrder',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
                ('id', models.BigAutoField(primary_key=True, serialize=False)),
                ('order_date', models.DateField(verbose_name='订单日期')),
                ('total_amount', models.DecimalField(decimal_places=2, max_digits=15, verbose_name='总金额')),
                ('remarks', models.TextField(blank=True, null=True, verbose_name='备注')),
                ('merchant', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='purchase_orders', to='basic_info.merchant', verbose_name='所属商户')),
                ('supplier', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='purchase_orders', to='basic_info.supplier', verbose_name='供应商')),
            ],
            options={
                'verbose_name': '采购单',
                'verbose_name_plural': '采购单',
            },
        ),
        migrations.CreateModel(
            name='StockChangeRecord',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
                ('id', models.BigAutoField(primary_key=True, serialize=False)),
                ('type', models.IntegerField(choices=[(1, '入库'), (2, '出库')], verbose_name='变动类型')),
                ('source_type', models.IntegerField(choices=[(1, '采购'), (2, '销退'), (3, '调入'), (4, '盘盈'), (5, '销售'), (6, '采购退货'), (7, '调出'), (8, '盘亏')], verbose_name='变动来源')),
                ('source_id', models.BigIntegerField(blank=True, null=True, verbose_name='来源单据ID')),
                ('is_finished', models.BooleanField(default=False, verbose_name='完成出入库')),
                ('finished_at', models.DateTimeField(blank=True, null=True, verbose_name='完成时间')),
                ('remarks', models.TextField(blank=True, null=True, verbose_name='备注')),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='操作人')),
                ('merchant', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='stock_change_records', to='basic_info.merchant', verbose_name='所属商户')),
                ('warehouse', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='stock_change_records', to='basic_info.warehouse', verbose_name='仓库')),
            ],
            options={
                'verbose_name': '出入库记录',
                'verbose_name_plural': '出入库记录',
            },
        ),
        migrations.CreateModel(
            name='StockChangeDetail',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
                ('id', models.BigAutoField(primary_key=True, serialize=False)),
                ('quantity', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='数量')),
                ('unit', models.IntegerField(choices=[(1, '米'), (2, '码'), (3, '公斤')], verbose_name='单位')),
                ('merchant', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='stock_change_details', to='basic_info.merchant', verbose_name='所属商户')),
                ('product', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='stock_change_details', to='basic_info.product', verbose_name='产品')),
                ('stock_change_record', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='details', to='stock.stockchangerecord', verbose_name='库存变动记录')),
            ],
            options={
                'verbose_name': '库存变动明细',
                'verbose_name_plural': '库存变动明细',
            },
        ),
        migrations.CreateModel(
            name='StockSnapshot',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
                ('id', models.BigAutoField(primary_key=True, serialize=False)),
                ('delta', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='库存变动数量')),
                ('quantity_before', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='变动前库存数量')),
                ('quantity_after', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='变动后库存数量')),
                ('unit', models.IntegerField(choices=[(1, '米'), (2, '码'), (3, '公斤')], verbose_name='单位')),
                ('num_of_rolls', models.IntegerField(default=1, verbose_name='匹数')),
                ('offset_to', models.BigIntegerField(blank=True, null=True, verbose_name='冲抵目标ID')),
                ('offset_at', models.DateTimeField(blank=True, null=True, verbose_name='冲抵时间')),
                ('cancelled', models.BooleanField(default=False, verbose_name='已取消')),
                ('cancelled_at', models.DateTimeField(blank=True, null=True, verbose_name='取消时间')),
                ('offset_id', models.BigIntegerField(blank=True, null=True, verbose_name='冲抵记录ID')),
                ('merchant', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='stock_snapshots', to='basic_info.merchant', verbose_name='所属商户')),
                ('product', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='stock_snapshots', to='basic_info.product', verbose_name='产品')),
                ('stock_change_record', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='stock_snapshots', to='stock.stockchangerecord', verbose_name='关联的库存变动记录')),
                ('warehouse', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='stock_snapshots', to='basic_info.warehouse', verbose_name='仓库')),
            ],
            options={
                'verbose_name': '库存快照',
                'verbose_name_plural': '库存快照',
            },
        ),
        migrations.CreateModel(
            name='Inventory',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
                ('id', models.BigAutoField(primary_key=True, serialize=False)),
                ('quantity', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='库存数量')),
                ('num_of_rolls', models.IntegerField(default=1, verbose_name='匹数')),
                ('minimum_quantity', models.IntegerField(blank=True, null=True, verbose_name='最低库存量')),
                ('spec', models.CharField(blank=True, max_length=100, null=True, verbose_name='规格')),
                ('description', models.TextField(blank=True, null=True, verbose_name='备注描述')),
                ('merchant', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='inventories', to='basic_info.merchant', verbose_name='所属商户')),
                ('product', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='inventories', to='basic_info.product', verbose_name='产品')),
                ('warehouse', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='inventories', to='basic_info.warehouse', verbose_name='仓库')),
            ],
            options={
                'verbose_name': '库存',
                'verbose_name_plural': '库存',
                'unique_together': {('product', 'warehouse')},
            },
        ),
    ]
