Make club app a little more manageable.
[wolnelektury.git] / src / club / migrations / 0013_populate_payed_at.py
diff --git a/src/club/migrations/0013_populate_payed_at.py b/src/club/migrations/0013_populate_payed_at.py
new file mode 100644 (file)
index 0000000..68b335e
--- /dev/null
@@ -0,0 +1,26 @@
+# 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)
+    ]