# Generated by Django 2.2.13 on 2020-08-07 08:22

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


def assign_default_order_number(apps, schema_editor):
    Order = apps.get_model("payments", "Order")
    for order in Order.objects.all():
        order.order_number = payments.utils.generate_order_number()
        order.save(update_fields=["order_number"])


class Migration(migrations.Migration):

    dependencies = [
        ("payments", "0004_make_order_lease_unique"),
    ]

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