From 792203d45ba0ccad8778a6047e1887444252bdfb Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Mon, 9 Jan 2017 23:37:04 +0100 Subject: [PATCH] Add Student.Payback --- teleforma/admin.py | 7 ++++++- teleforma/models/crfpa.py | 20 ++++++++++++++++++++ teleforma/views/crfpa.py | 4 +++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/teleforma/admin.py b/teleforma/admin.py index e8a33f76..2f3b049b 100644 --- a/teleforma/admin.py +++ b/teleforma/admin.py @@ -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', diff --git a/teleforma/models/crfpa.py b/teleforma/models/crfpa.py index 454c5981..640e0dad 100644 --- a/teleforma/models/crfpa.py +++ b/teleforma/models/crfpa.py @@ -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") diff --git a/teleforma/views/crfpa.py b/teleforma/views/crfpa.py index 0f0ef24d..9e78c0e3 100644 --- a/teleforma/views/crfpa.py +++ b/teleforma/views/crfpa.py @@ -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: -- 2.39.5