]> git.parisson.com Git - teleforma.git/commitdiff
Add Student.Payback
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 9 Jan 2017 22:37:04 +0000 (23:37 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 9 Jan 2017 22:37:04 +0000 (23:37 +0100)
teleforma/admin.py
teleforma/models/crfpa.py
teleforma/views/crfpa.py

index e8a33f7669f67bf8435c1da94f2c356443a909d9..2f3b049b2bea7ff1c2c9f10a4f1fa60e7089d5ea 100644 (file)
@@ -14,6 +14,7 @@ from django.core import serializers
 from django.contrib.admin.helpers import ActionForm
 from django import forms
 
+
 class PeriodListFilter(SimpleListFilter):
 
     title = _('period')
@@ -54,6 +55,10 @@ class DiscountInline(admin.StackedInline):
     model = Discount
     extra = 1
 
+class PaybackInline(admin.StackedInline):
+    model = Payback
+    extra = 1
+
 class StudentInline(admin.StackedInline):
     model = Student
     extra = 1
@@ -70,7 +75,7 @@ class StudentAdmin(admin.ModelAdmin):
     model = Student
     exclude = ['options']
     filter_horizontal = ['trainings']
-    inlines = [PaymentInline, OptionalFeeInline, DiscountInline]
+    inlines = [PaymentInline, OptionalFeeInline, DiscountInline, PaybackInline]
     search_fields = ['user__first_name', 'user__last_name', 'user__username']
     list_filter = ['user__is_active', 'is_subscribed', 'platform_only', PeriodListFilter,
                     'trainings', 'iej', 'procedure', 'written_speciality', 'oral_speciality',
index 454c5981a675d4fa4f110234cb0ec634c52ba3cc..640e0dad4e0d1f3319b0b5407d450af4103e237e 100644 (file)
@@ -184,6 +184,13 @@ class Student(Model):
             amount -= discount.value
         return amount
 
+    @property
+    def total_paybacks(self):
+        amount = 0
+        for payback in self.paybacks.all():
+            amount -= payback.value
+        return amount
+
     @property
     def balance(self):
         return  round(self.total_payments - self.total_fees, 2)
@@ -266,3 +273,16 @@ class OptionalFee(models.Model):
         db_table = app_label + '_' + 'optional_fees'
         verbose_name = _("Optional fees")
         verbose_name_plural = _("Optional fees")
+
+
+class Payback(models.Model):
+    "an payback for a student subscription"
+
+    student = models.ForeignKey(Student, related_name='paybacks', verbose_name=_('student'))
+    value = models.FloatField(_('amount'), help_text='€')
+    description = models.CharField(_('description'), max_length=255, blank=True)
+
+    class Meta(MetaCore):
+        db_table = app_label + '_' + 'paybacks'
+        verbose_name = _("Payback")
+        verbose_name_plural = _("Paybacks")
index 0f0ef24d88e184cd9c082d176d744cdd9a3de234..9e78c0e39ecd66d02b87a26cf2f93ab485077b34 100644 (file)
@@ -261,9 +261,10 @@ class UserXLSBook(object):
                 row.write(18, student.total_payments)
                 row.write(19, student.total_fees)
                 row.write(20, student.balance)
+                row.write(21, student.total_paybacks)
 
                 payments = student.payments.all()
-                i = 21
+                i = 22
                 for month in months_choices:
                     payment = payments.filter(month=month[0])
                     if payment:
@@ -300,6 +301,7 @@ class UserXLSBook(object):
                 {'name':"Total paiements", 'width':4000},
                 {'name':"Prix formation net", 'width':4000},
                 {'name':"Balance", 'width':4000},
+                {'name':"Total remboursement", 'width':4000},
                 ]
 
         for month in months_choices: