# Generated by Django 2.2.5 on 2020-09-14 14:50

from django.db import migrations, models


def forwards_func(apps, schema_editor):
    # We get the model from the versioned app registry;
    # if we directly import it, it'll be the wrong version
    Order = apps.get_model('wagtailcommerce_orders', 'Order')
    db_alias = schema_editor.connection.alias

    for order in Order.objects.using(db_alias).all():
        for line in order.lines.all():
            line.item_unit_price = line.item_unit_regular_price
            line.save()


def reverse_func(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('wagtailcommerce_orders', '0025_auto_20200912_0218'),
    ]

    operations = [
        migrations.RenameField(
            model_name='orderline',
            old_name='item_discount',
            new_name='item_unit_promotions_discount'
        ),
        migrations.RenameField(
            model_name='orderline',
            old_name='item_price',
            new_name='item_unit_regular_price'
        ),
        migrations.RenameField(
            model_name='orderline',
            old_name='item_price_with_discount',
            new_name='item_unit_price_with_promotions_discount'
        ),
        migrations.AddField(
            model_name='orderline',
            name='item_percentage_discount',
            field=models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True, verbose_name='item percentage discount'),
        ),
        migrations.AddField(
            model_name='orderline',
            name='item_unit_price',
            field=models.DecimalField(decimal_places=2, default=0, max_digits=12, verbose_name='item unit price'),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name='orderline',
            name='item_unit_sale_price',
            field=models.DecimalField(blank=True, decimal_places=2, default=0, max_digits=12, null=True, verbose_name='item unit sale price'),
            preserve_default=False,
        ),
        migrations.AlterField(
            model_name='orderline',
            name='item_unit_price_with_promotions_discount',
            field=models.DecimalField(decimal_places=2, max_digits=12, verbose_name='item price with promotions discount'),
        ),
        migrations.AlterField(
            model_name='orderline',
            name='item_unit_promotions_discount',
            field=models.DecimalField(decimal_places=2, max_digits=12, verbose_name='total discounted from each unit based on promotions'),
        ),
        migrations.AlterField(
            model_name='orderline',
            name='item_unit_regular_price',
            field=models.DecimalField(decimal_places=2, max_digits=12, verbose_name='item unit regular price'),
        ),
        migrations.RunPython(forwards_func, reverse_func)
    ]
