from decimal import Decimal

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('basic_info', '0026_transportvehicle_and_capacity'),
        ('business', '0028_payment_receipt_external_source_fields'),
    ]

    operations = [
        migrations.CreateModel(
            name='ExternalCustomerStatementOrder',
            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)),
                ('category', models.CharField(choices=[('sale', '外部销售单'), ('sale_return', '外部销售退货单')], max_length=20, verbose_name='外部业务分类')),
                ('external_customer_id', models.CharField(blank=True, default='', max_length=100, verbose_name='外部客户ID')),
                ('external_source_id', models.CharField(db_index=True, max_length=100, verbose_name='外部单号')),
                ('occurred_at', models.DateField(verbose_name='业务日期')),
                ('recorded_at', models.DateTimeField(blank=True, null=True, verbose_name='录单时间')),
                ('settlement_method', models.CharField(blank=True, default='', max_length=100, verbose_name='结算方式')),
                ('total_amount', models.DecimalField(decimal_places=2, default=Decimal('0'), max_digits=15, verbose_name='总金额')),
                ('remarks', models.TextField(blank=True, null=True, verbose_name='备注')),
                ('items_payload', models.JSONField(blank=True, default=list, verbose_name='明细快照')),
                ('extra_payload', models.JSONField(blank=True, default=dict, verbose_name='扩展数据')),
                ('customer', models.ForeignKey(on_delete=models.deletion.PROTECT, related_name='external_statement_orders', to='basic_info.customer', verbose_name='客户')),
                ('merchant', models.ForeignKey(on_delete=models.deletion.PROTECT, related_name='external_customer_statement_orders', to='basic_info.merchant', verbose_name='所属商户')),
            ],
            options={
                'verbose_name': '外部客户对账来源单',
                'verbose_name_plural': '外部客户对账来源单',
            },
        ),
        migrations.AddConstraint(
            model_name='externalcustomerstatementorder',
            constraint=models.UniqueConstraint(fields=('merchant', 'category', 'external_source_id'), name='uniq_external_customer_statement_order_source'),
        ),
    ]