# Generated by Django 2.2.5 on 2019-09-30 13:13
import json
from django.db import migrations


def populate_payed_at(apps, schema_editor):
    PayUNotification = apps.get_model('club', 'PayUNotification')
    for notification in PayUNotification.objects.order_by('received_at'):
        status = json.loads(notification.body)['order']['status']
        schedule = notification.order.schedule
        if status == 'COMPLETED' and schedule.payed_at is None:
            schedule.payed_at = notification.received_at
            schedule.save()

class Migration(migrations.Migration):

    dependencies = [
        ('club', '0012_auto_20190930_1510'),
    ]

    operations = [
        migrations.RunPython(
            populate_payed_at,
            migrations.RunPython.noop,
            elidable=True)
    ]
