Browse Source

affichage des cotisations

Élie Bouttier 7 years ago
parent
commit
d35a655441
3 changed files with 20 additions and 8 deletions
  1. 2 2
      adhesions/templates/adhesions/_adhesion_detail.html
  2. 6 1
      banking/admin.py
  3. 12 5
      banking/models.py

+ 2 - 2
adhesions/templates/adhesions/_adhesion_detail.html

@@ -10,8 +10,8 @@
         <p>Adhérent : <a href="{{ adhesion.get_adherent_detail_url }}">{{ adhesion.get_adherent_name }}</a></p>
         {% endif %}
         <p>Numéro d’adhérent : ADT{{ adhesion.id }}</p>
-        {% if adhesion.contribution %}
-        <p>Montant de la cotisation : {{ adhesion.contribution }}</p>
+        {% if adhesion.membership.active %}
+        <p>Cotisation : {{ adhesion.membership }}</p>
         {% else %}
         <p>Pas de cotisation.</p>
         {% endif %}

+ 6 - 1
banking/admin.py

@@ -126,7 +126,7 @@ def prefix_search_field(prefix, field):
 ### ModelAdmin
 
 class RecurringPaymentAdmin(admin.ModelAdmin):
-    list_display = ('id', 'payment_type', 'payment_object_link', 'get_status', 'get_last_validated_update', 'get_pending',)
+    list_display = ('id', 'payment_type', 'payment_object_link', 'get_active', 'get_last_validated_update', 'get_pending',)
     list_select_related = ('adhesion', 'service', 'service__service_type',)
     inlines = (PendingPaymentUpdateInline, ValidatedPaymentUpdateInline,)
     list_filter = (PaymentTypeFilter, PaymentStatusFilter, PendingPaymentFilter,)
@@ -152,6 +152,11 @@ class RecurringPaymentAdmin(admin.ModelAdmin):
         return len(obj.pending_updates)
     get_pending.short_description = 'Opérations en attente'
 
+    def get_active(self, obj):
+        return obj.active
+    get_active.short_description = 'Actif'
+    get_active.boolean = True
+
     def payment_object_link(self, obj):
         obj = obj.payment_object()
         return format_html(u'<a href="{}">{}</a>', obj.get_absolute_url(), obj)

+ 12 - 5
banking/models.py

@@ -24,11 +24,18 @@ class RecurringPayment(models.Model):
     def get_absolute_url(self):
         return reverse('admin:%s_%s_change' % (self._meta.app_label, self._meta.model_name), args=(self.pk,))
 
-    def get_status(self):
+    @property
+    def active(self):
         payment = self.get_last_validated_update()
         return payment is not None and payment.payment_method != PaymentUpdate.STOP
-    get_status.short_description = 'Actif'
-    get_status.boolean = True
+
+    @property
+    def amount(self):
+        payment = self.get_last_validated_update()
+        if payment is not None and payment.payment_method != PaymentUpdate.STOP:
+            return payment.amount
+        else:
+            return None
 
     class Meta:
         verbose_name = 'paiement récurrent'
@@ -89,6 +96,8 @@ class PaymentUpdate(models.Model):
     def __str__(self):
         if self.payment_method == self.STOP:
             return 'paiement arrêté'
+        if self.payment_method == self.FREE:
+            return 'libre'
         s = str(self.amount) + '€'
         if self.period:
             if self.period == 1:
@@ -101,6 +110,4 @@ class PaymentUpdate(models.Model):
             s += ' (prélèvement)'
         elif self.payment_method == self.TRANSFER:
             s += ' (virement)'
-        elif self.payment_method == self.CASH:
-            s += ' (liquide)'
         return s