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


class Migration(migrations.Migration):

    dependencies = [
        ("shipment", "0018_salesitem_soft_delete_fields"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="SalesItemRebuildRecord",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
                ("rebuilt_at", models.DateTimeField(verbose_name="重建时间")),
                ("old_printing_job_id", models.PositiveIntegerField(blank=True, null=True, verbose_name="旧生产任务ID")),
                ("new_printing_job_id", models.PositiveIntegerField(verbose_name="新生产任务ID")),
                ("old_quantity", models.DecimalField(decimal_places=2, max_digits=12, verbose_name="旧数量")),
                ("new_quantity", models.DecimalField(decimal_places=2, max_digits=12, verbose_name="新数量")),
                (
                    "new_sales_item",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="rebuild_target_records",
                        to="shipment.salesitem",
                        verbose_name="新销售品",
                    ),
                ),
                (
                    "old_sales_item",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="rebuild_source_records",
                        to="shipment.salesitem",
                        verbose_name="旧销售品",
                    ),
                ),
                (
                    "operator",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="sales_item_rebuild_records",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="操作者",
                    ),
                ),
            ],
            options={
                "verbose_name": "销售品重建记录",
                "verbose_name_plural": "销售品重建记录",
                "db_table": "sales_item_rebuild_record",
                "ordering": ["-rebuilt_at", "-id"],
            },
        ),
    ]
