Form thank you
[wolnelektury.git] / src / club / migrations / 0013_populate_payed_at.py
1 # Generated by Django 2.2.5 on 2019-09-30 13:13
2 import json
3 from django.db import migrations
4
5
6 def populate_payed_at(apps, schema_editor):
7     PayUNotification = apps.get_model('club', 'PayUNotification')
8     for notification in PayUNotification.objects.order_by('received_at'):
9         status = json.loads(notification.body)['order']['status']
10         schedule = notification.order.schedule
11         if status == 'COMPLETED' and schedule.payed_at is None:
12             schedule.payed_at = notification.received_at
13             schedule.save()
14
15 class Migration(migrations.Migration):
16
17     dependencies = [
18         ('club', '0012_auto_20190930_1510'),
19     ]
20
21     operations = [
22         migrations.RunPython(
23             populate_payed_at,
24             migrations.RunPython.noop,
25             elidable=True)
26     ]