# Generated by Django 2.2.4 on 2019-08-29 07:49

from django.db import migrations, models


def add_variant_name_to_order_line(apps, schema_editor):
    cls = apps.get_model("order", "OrderLine")
    order_lines = cls.objects.all()

    for order_line in order_lines:
        if order_line.variant:
            variant_name = order_line.variant.name or order_line.variant.sku
            order_line.variant_name = variant_name
            order_line.product_name = order_line.variant.product.name
            order_line.save(update_fields=["variant_name", "product_name"])


class Migration(migrations.Migration):

    dependencies = [("order", "0072_django_price_2")]

    operations = [
        migrations.AddField(
            model_name="orderline",
            name="translated_variant_name",
            field=models.CharField(blank=True, default="", max_length=255),
        ),
        migrations.AddField(
            model_name="orderline",
            name="variant_name",
            field=models.CharField(blank=True, default="", max_length=255),
        ),
        migrations.RunPython(add_variant_name_to_order_line),
    ]
