Browse Source

màj script transparence

Élie Bouttier 7 years ago
parent
commit
037bb0d807
2 changed files with 14 additions and 8 deletions
  1. 10 8
      banking/management/commands/transparence.py
  2. 4 0
      banking/models.py

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

@@ -26,11 +26,9 @@ class Command(BaseCommand):
         ttnn = Adhesion.objects.get(id=100)
         total = [0, 0, 0, 0, 0, 0, 0]
         lines = []
-        for service_type in ServiceType.objects.all():
+        for service_type in ServiceType.objects.exclude(name='Contribution'):
             ntotal = ninf = nadh = npay = nfree = nmiss = income = 0
-            for service in service_type.services.all():
-                if not service.is_active():
-                    continue
+            for service in service_type.services.filter(get_active_filter('allocation')).order_by('pk').distinct():
                 ntotal += 1
                 if service.adhesion == ttnn:
                     ninf += 1
@@ -48,7 +46,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("%-18s%12s%12s%12s%12s%12s%12s%12s" % ('Service', 'total', 'infra', 'adhérents', 'gratuits', 'payés', 'euros', 'pourcent'))
+        self.stdout.write("%-18s%12s%12s%12s%12s%12s%12s%12s%12s%12s" % ('Service', 'total', 'infra', 'adhérents', 'gratuits', 'manquants', 'payés', 'euros', 'moyenne', 'pourcent'))
         lines += [('TOTAL',) + tuple(total)]
         total_income = total[6]
         for service_type, ntotal, ninf, nadh, npay, nfree, nmiss, income in lines:
@@ -56,7 +54,11 @@ class Command(BaseCommand):
                 percent = income / total_income * 100
             else:
                 percent = 0
-            self.stdout.write("%-18s%12d%12d%12d%12d%12d%12.2f%12.1f" % (service_type, ntotal, ninf, nadh, nfree + nmiss, npay, income, percent))
+            if npay:
+                moy = income / npay
+            else:
+                moy = float('nan')
+            self.stdout.write("%-18s%12d%12d%12d%12d%12d%12d%12.2f%12.2f%12.1f" % (service_type, ntotal, ninf, nadh, nfree, nmiss, npay, income, moy, percent))
 
     def handle_adhesions(self):
         adhesions = Adhesion.objects.filter(Q(active__isnull=True) | Q(active=True))
@@ -72,5 +74,5 @@ class Command(BaseCommand):
                 assert(payment.payment_method != PaymentUpdate.STOP)
                 ppay += 1
                 income += float(payment.amount) / payment.period
-        self.stdout.write("%12s%12s%12s%12s" % ('Adhesions', 'gratuites', 'payées', 'euros'))
-        self.stdout.write("%12d%12d%12d%12d" % (nadh, pgra + pmiss, ppay, income))
+        self.stdout.write("%12s%12s%12s%12s%12s%12s" % ('Adhesions', 'gratuites', 'manquantes', 'payées', 'euros', 'moyenne'))
+        self.stdout.write("%12d%12d%12d%12d%12.2f%12.2f" % (nadh, pgra, pmiss, ppay, income, 12 * income / ppay))

+ 4 - 0
banking/models.py

@@ -133,4 +133,8 @@ class PaymentUpdate(models.Model):
             s += ' (prélèvement)'
         elif self.payment_method == self.TRANSFER:
             s += ' (virement)'
+        elif self.payment_method == self.CASH:
+            s += ' (liquide)'
+        elif self.payment_method == self.INVOICE:
+            s += ' (sur facture)'
         return s