# Generated by Django 5.0 on 2026-03-16 07:11

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


class Migration(migrations.Migration):

    dependencies = [
        ('fertilizer', '0006_fertilizationplan_confirmation'),
        ('fields', '0006_e1c_chusankan_17_fields'),
    ]

    operations = [
        migrations.CreateModel(
            name='DeliveryGroup',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=100, verbose_name='グループ名')),
                ('order', models.PositiveIntegerField(default=0, verbose_name='表示順')),
            ],
            options={
                'verbose_name': '配送先グループ',
                'verbose_name_plural': '配送先グループ',
                'ordering': ['order', 'id'],
            },
        ),
        migrations.CreateModel(
            name='DeliveryPlan',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('year', models.IntegerField(verbose_name='年度')),
                ('name', models.CharField(max_length=200, verbose_name='計画名')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': '運搬計画',
                'verbose_name_plural': '運搬計画',
                'ordering': ['-year', 'name'],
            },
        ),
        migrations.RemoveField(
            model_name='distributiongroupfield',
            name='group',
        ),
        migrations.AlterUniqueTogether(
            name='distributiongroupfield',
            unique_together=None,
        ),
        migrations.RemoveField(
            model_name='distributiongroupfield',
            name='distribution_plan',
        ),
        migrations.RemoveField(
            model_name='distributiongroupfield',
            name='field',
        ),
        migrations.RemoveField(
            model_name='distributionplan',
            name='fertilization_plan',
        ),
        migrations.CreateModel(
            name='DeliveryGroupField',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('field', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='fields.field', verbose_name='圃場')),
                ('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='field_assignments', to='fertilizer.deliverygroup', verbose_name='グループ')),
                ('delivery_plan', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fertilizer.deliveryplan', verbose_name='運搬計画')),
            ],
            options={
                'verbose_name': 'グループ圃場割り当て',
                'verbose_name_plural': 'グループ圃場割り当て',
                'ordering': ['field__display_order', 'field__id'],
                'unique_together': {('delivery_plan', 'field')},
            },
        ),
        migrations.AddField(
            model_name='deliverygroup',
            name='delivery_plan',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='groups', to='fertilizer.deliveryplan', verbose_name='運搬計画'),
        ),
        migrations.CreateModel(
            name='DeliveryTrip',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('order', models.PositiveIntegerField(default=0, verbose_name='何回目')),
                ('name', models.CharField(blank=True, max_length=100, verbose_name='名前')),
                ('date', models.DateField(blank=True, null=True, verbose_name='運搬日')),
                ('delivery_plan', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='trips', to='fertilizer.deliveryplan', verbose_name='運搬計画')),
            ],
            options={
                'verbose_name': '運搬回',
                'verbose_name_plural': '運搬回',
                'ordering': ['order', 'id'],
            },
        ),
        migrations.CreateModel(
            name='DeliveryTripItem',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('bags', models.DecimalField(decimal_places=4, max_digits=10, verbose_name='袋数')),
                ('fertilizer', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='fertilizer.fertilizer', verbose_name='肥料')),
                ('field', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='fields.field', verbose_name='圃場')),
                ('trip', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='fertilizer.deliverytrip', verbose_name='運搬回')),
            ],
            options={
                'verbose_name': '運搬明細',
                'verbose_name_plural': '運搬明細',
                'ordering': ['field__display_order', 'field__id', 'fertilizer__name'],
                'unique_together': {('trip', 'field', 'fertilizer')},
            },
        ),
        migrations.DeleteModel(
            name='DistributionGroup',
        ),
        migrations.DeleteModel(
            name='DistributionGroupField',
        ),
        migrations.DeleteModel(
            name='DistributionPlan',
        ),
        migrations.AlterUniqueTogether(
            name='deliverygroup',
            unique_together={('delivery_plan', 'name')},
        ),
    ]
