# -*- coding: utf-8 -*-
# Generated by Django 1.9.3 on 2016-03-08 13:15
from __future__ import unicode_literals

from django.db import migrations, models


def update_order_to_pay(apps, schema_editor):
    Order = apps.get_model('app', 'Order')
    orders = Order.objects.all()
    for order in orders:
        order.to_pay = max(order.total - (
                order.coupon.amount if order.coupon else 0), 0)
        order.save()


class Migration(migrations.Migration):

    dependencies = [
        ('app', '0103_weixintoken_expires_in'),
    ]

    operations = [
        migrations.AddField(
            model_name='order',
            name='to_pay',
            field=models.PositiveIntegerField(default=0),
        ),
        migrations.RunPython(update_order_to_pay),
    ]
