# Generated by Django 3.1.7 on 2021-04-12 13:35

from django.db import migrations, models
import payments.utils


def assign_default_offer_number(apps, schema_editor):
    BerthSwitchOffer = apps.get_model("payments", "BerthSwitchOffer")
    for offer in BerthSwitchOffer.objects.all():
        offer.offer_number = payments.utils.generate_order_number()
        offer.save(update_fields=["offer_number"])


class Migration(migrations.Migration):

    dependencies = [
        ("payments", "0026_split_offer_pending_status"),
    ]

    operations = [
        migrations.AddField(
            model_name="berthswitchoffer",
            name="offer_number",
            field=models.CharField(
                max_length=64,
                null=True,
                verbose_name="offer number",
            ),
        ),
        migrations.RunPython(
            assign_default_offer_number, reverse_code=migrations.RunPython.noop
        ),
        migrations.AlterField(
            model_name="berthswitchoffer",
            name="offer_number",
            field=models.CharField(
                db_index=True,
                default=payments.utils.generate_order_number,
                editable=False,
                max_length=64,
                unique=True,
                verbose_name="offer number",
            ),
        ),
    ]
