Browse Source

fix transparence

Élie Bouttier 7 years ago
parent
commit
5c327052ed
1 changed files with 11 additions and 8 deletions
  1. 11 8
      banking/management/commands/transparence.py

+ 11 - 8
banking/management/commands/transparence.py

@@ -1,4 +1,5 @@
 from django.core.management.base import BaseCommand, CommandError
+from django.db.models import Q
 
 from adhesions.models import Adhesion
 from services.models import Service, ServiceType, IPResource, Route
@@ -35,7 +36,7 @@ class Command(BaseCommand):
                     ninf += 1
                     continue
                 nadh += 1
-                contrib = service.contribution.get_last_validated_update()
+                contrib = service.contribution.current
                 if not contrib or contrib.payment_method == PaymentUpdate.STOP:
                     nmiss += 1
                 elif contrib.payment_method == PaymentUpdate.FREE:
@@ -47,7 +48,7 @@ class Command(BaseCommand):
             assert(nadh == npay + nfree + nmiss)
             total = list(map(add, total, [ntotal, ninf, nadh, npay, nfree, nmiss, income]))
             lines += [(str(service_type), ntotal, ninf, nadh, npay, nfree, nmiss, income)]
-        self.stdout.write("%-16s%12s%12s%12s%12s%12s%12s%12s" % ('Service', 'total', 'infra', 'adhérents', 'gratuit', 'manquant', 'euros', 'pourcent'))
+        self.stdout.write("%-18s%12s%12s%12s%12s%12s%12s%12s" % ('Service', 'total', 'infra', 'adhérents', 'gratuit', 'manquant', 'euros', 'pourcent'))
         lines += [('TOTAL',) + tuple(total)]
         total_income = total[5]
         for service_type, ntotal, ninf, nadh, npay, nfree, nmiss, income in lines:
@@ -55,19 +56,21 @@ class Command(BaseCommand):
                 percent = income / total_income * 100
             else:
                 percent = 0
-            self.stdout.write("%-16s%12d%12d%12d%12d%12d%12.2f%12.1f" % (service_type, ntotal, ninf, nadh, nfree, nmiss, income, percent))
+            self.stdout.write("%-18s%12d%12d%12d%12d%12d%12.2f%12.1f" % (service_type, ntotal, ninf, nadh, nfree, nmiss, income, percent))
 
     def handle_adhesions(self):
-        adhesions = Adhesion.objects.select_related('membership').exclude(active=False)
+        adhesions = Adhesion.objects.filter(Q(active__isnull=True) | Q(active=True))
         nadh = adhesions.count()
         pmiss, pgra, ppay, income = 0, 0, 0, 0
-        payments = map(lambda adh: adh.membership.get_last_validated_update(), adhesions)
+        payments = map(lambda adh: adh.membership.current, adhesions)
         for payment in payments:
-            if payment is None or payment.payment_method == PaymentUpdate.STOP:
+            if payment is None:
                 pmiss += 1
             elif payment.payment_method == PaymentUpdate.FREE:
                 pgra += 1
             else:
+                assert(payment.payment_method != PaymentUpdate.STOP)
+                ppay += 1
                 income += float(payment.amount) / payment.period
-        self.stdout.write("%12s%12s%12s%12s" % ('Adhesions', 'gratuit', 'manquante', 'euros'))
-        self.stdout.write("%12d%12d%12d%12d" % (nadh, pgra, pmiss, income))
+        self.stdout.write("%12s%12s%12s%12s%12s" % ('Adhesions', 'payant', 'gratuit', 'manquante', 'euros'))
+        self.stdout.write("%12d%12d%12d%12d%12d" % (nadh, ppay, pgra, pmiss, income))