]> git.parisson.com Git - teleforma.git/commitdiff
Added commands for db cleanup
authorGael Le Mignot <gael@pilotsystems.net>
Thu, 1 Apr 2021 07:12:14 +0000 (09:12 +0200)
committerGael Le Mignot <gael@pilotsystems.net>
Thu, 1 Apr 2021 07:12:14 +0000 (09:12 +0200)
teleforma/management/commands/teleforma-cleanup-dup-discounts.py [new file with mode: 0644]
teleforma/management/commands/teleforma-fixate-oral-fees.py [new file with mode: 0644]
teleforma/management/commands/teleforma-prefill-payment-schedules.py [new file with mode: 0644]

diff --git a/teleforma/management/commands/teleforma-cleanup-dup-discounts.py b/teleforma/management/commands/teleforma-cleanup-dup-discounts.py
new file mode 100644 (file)
index 0000000..5f4ff27
--- /dev/null
@@ -0,0 +1,17 @@
+from django.core.management.base import BaseCommand
+from teleforma.models import *
+
+class Command(BaseCommand):
+    help = "Cleanup duplicate discount objects"
+
+    def handle(self, *args, **options):
+        for student in Student.objects.all():
+            known = set()
+            for discount in student.discounts.all():
+                key = (discount.value, discount.description)
+                if key in known:
+                    print("Deleting %d (%s: %s)" % (discount.id, student, key))
+                    discount.delete()
+                else:
+                    known.add(key)
+
diff --git a/teleforma/management/commands/teleforma-fixate-oral-fees.py b/teleforma/management/commands/teleforma-fixate-oral-fees.py
new file mode 100644 (file)
index 0000000..7254045
--- /dev/null
@@ -0,0 +1,38 @@
+from django.core.management.base import BaseCommand
+from teleforma.models import *
+
+import datetime
+
+class Command(BaseCommand):
+    help = "Create missing schedule objects"
+
+    def handle(self, *args, **options):
+        date = datetime.date(2021, 8, 31)
+        amount = 250
+        
+        for student in Student.objects.all():
+            if not student.date_subscribed or not student.period or not student.oral_1:
+                continue
+            if student.period.name != 'Estivale':
+                continue
+            if student.payment_type != 'online':
+                continue
+            if student.oral_1.title != 'Anglais':
+                continue
+
+            found = False
+            for fee in student.optional_fees.all():
+                if fee.value == amount:
+                    found = True
+            if found:
+                continue
+            p = Payment(student = student,
+                        value = amount,
+                        month = date.month,
+                        scheduled = date)
+            p.save()
+            f = OptionalFee(student = student,
+                            value = amount,
+                            description = "Option langue")
+            f.save()
+            print("Student %d: created %d / %d" % (student.id, p.id, f.id))
diff --git a/teleforma/management/commands/teleforma-prefill-payment-schedules.py b/teleforma/management/commands/teleforma-prefill-payment-schedules.py
new file mode 100644 (file)
index 0000000..c9af91e
--- /dev/null
@@ -0,0 +1,48 @@
+from django.core.management.base import BaseCommand
+from teleforma.models import *
+
+import datetime
+
+class Command(BaseCommand):
+    help = "Create missing schedule objects"
+
+    def handle(self, *args, **options):
+        threshold = datetime.date(2021, 2, 2)
+        tomorrow = datetime.date.today() + datetime.timedelta(days=1)
+
+        date1 = datetime.date(2021, 6, 30)
+        date2 = datetime.date(2021, 7, 31)
+
+        full = ((0.30, tomorrow),
+                (0.35, date1),
+                (0.35, date2))
+        partial = ((0.5, date1),
+                   (0.5, date2))
+                
+        for student in Student.objects.all():
+            if not student.date_subscribed or not student.period:
+                continue
+            if student.period.name != 'Estivale':
+                continue
+            if student.date_subscribed.date() < threshold:
+                continue
+            if student.payment_type != 'online':
+                continue
+            student.update_balance()
+            if student.balance_intermediary >= 0:
+                continue            
+
+            if len(student.payments.all()) > 0:
+                schedule = partial
+            else:
+                schedule = full
+
+            balance = student.balance_intermediary
+            for ratio, date in schedule:
+                amount = -balance * ratio
+                p = Payment(student = student,
+                            value = amount,
+                            month = date.month,
+                            scheduled = date)
+                p.save()
+                print("Student %d: created %d" % (student.id, p.id))