🐛 Fix treasury

This commit is contained in:
Yohann D'ANELLO 2020-08-05 18:04:01 +02:00
parent 9c3e978a41
commit b0398e59b8
7 changed files with 86 additions and 80 deletions

View File

@ -1,11 +1,10 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import datetime
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit from crispy_forms.layout import Submit
from django import forms from django import forms
from django.utils import timezone
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from note_kfet.inputs import DatePickerInput, AmountInput from note_kfet.inputs import DatePickerInput, AmountInput
@ -19,12 +18,13 @@ class InvoiceForm(forms.ModelForm):
# Django forms don't support date fields. We have to add it manually # Django forms don't support date fields. We have to add it manually
date = forms.DateField( date = forms.DateField(
initial=datetime.date.today, initial=timezone.now,
widget=DatePickerInput() widget=DatePickerInput(),
) )
def clean_date(self): def clean_date(self):
self.instance.date = self.data.get("date") self.instance.date = self.data.get("date")
return self.instance.date
class Meta: class Meta:
model = Invoice model = Invoice
@ -36,7 +36,11 @@ class ProductForm(forms.ModelForm):
model = Product model = Product
fields = '__all__' fields = '__all__'
widgets = { widgets = {
"amount": AmountInput() "amount": AmountInput(
attrs={
"negative": True,
}
)
} }
@ -115,6 +119,12 @@ class LinkTransactionToRemittanceForm(forms.ModelForm):
""" """
Attach a special transaction to a remittance. Attach a special transaction to a remittance.
""" """
remittance = forms.ModelChoiceField(
queryset=Remittance.objects.none(),
label=_("Remittance"),
empty_label=_("No attached remittance"),
required=False,
)
# Since we use a proxy model for special transactions, we add manually the fields related to the transaction # Since we use a proxy model for special transactions, we add manually the fields related to the transaction
last_name = forms.CharField(label=_("Last name")) last_name = forms.CharField(label=_("Last name"))
@ -123,7 +133,7 @@ class LinkTransactionToRemittanceForm(forms.ModelForm):
bank = forms.Field(label=_("Bank")) bank = forms.Field(label=_("Bank"))
amount = forms.IntegerField(label=_("Amount"), min_value=0) amount = forms.IntegerField(label=_("Amount"), min_value=0, widget=AmountInput(), disabled=True, required=False)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -133,33 +143,19 @@ class LinkTransactionToRemittanceForm(forms.ModelForm):
self.fields["remittance"].queryset = Remittance.objects.filter(closed=False) self.fields["remittance"].queryset = Remittance.objects.filter(closed=False)
def clean_last_name(self): def clean(self):
""" cleaned_data = super().clean()
Replace the first name in the information of the transaction. self.instance.transaction.last_name = cleaned_data["last_name"]
""" self.instance.transaction.first_name = cleaned_data["first_name"]
self.instance.transaction.last_name = self.data.get("last_name") self.instance.transaction.bank = cleaned_data["bank"]
self.instance.transaction.clean() return cleaned_data
def clean_first_name(self): def save(self, commit=True):
""" """
Replace the last name in the information of the transaction. Save the transaction and the remittance.
""" """
self.instance.transaction.first_name = self.data.get("first_name") self.instance.transaction.save()
self.instance.transaction.clean() return super().save(commit)
def clean_bank(self):
"""
Replace the bank in the information of the transaction.
"""
self.instance.transaction.bank = self.data.get("bank")
self.instance.transaction.clean()
def clean_amount(self):
"""
Replace the amount of the transaction.
"""
self.instance.transaction.amount = self.data.get("amount")
self.instance.transaction.clean()
class Meta: class Meta:
model = SpecialTransactionProxy model = SpecialTransactionProxy

View File

@ -82,7 +82,7 @@ class Product(models.Model):
verbose_name=_("Designation"), verbose_name=_("Designation"),
) )
quantity = models.PositiveIntegerField( quantity = models.IntegerField(
verbose_name=_("Quantity") verbose_name=_("Quantity")
) )

View File

@ -64,6 +64,7 @@ class RemittanceTable(tables.Table):
model = Remittance model = Remittance
template_name = 'django_tables2/bootstrap4.html' template_name = 'django_tables2/bootstrap4.html'
fields = ('id', 'date', 'remittance_type', 'comment', 'count', 'amount', 'view',) fields = ('id', 'date', 'remittance_type', 'comment', 'count', 'amount', 'view',)
order_by = ('-date',)
class SpecialTransactionTable(tables.Table): class SpecialTransactionTable(tables.Table):
@ -100,7 +101,8 @@ class SpecialTransactionTable(tables.Table):
} }
model = SpecialTransaction model = SpecialTransaction
template_name = 'django_tables2/bootstrap4.html' template_name = 'django_tables2/bootstrap4.html'
fields = ('id', 'source', 'destination', 'last_name', 'first_name', 'bank', 'amount', 'reason',) fields = ('created_at', 'source', 'destination', 'last_name', 'first_name', 'bank', 'amount', 'reason',)
order_by = ('-created_at',)
class SogeCreditTable(tables.Table): class SogeCreditTable(tables.Table):

View File

@ -238,7 +238,7 @@ class RemittanceListView(LoginRequiredMixin, TemplateView):
closed_remittances = RemittanceTable( closed_remittances = RemittanceTable(
data=Remittance.objects.filter(closed=True).filter( data=Remittance.objects.filter(closed=True).filter(
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).reverse().all(), PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all(),
prefix="closed-remittances-", prefix="closed-remittances-",
) )
closed_remittances.paginate(page=self.request.GET.get("closed-remittances-page", 1), per_page=10) closed_remittances.paginate(page=self.request.GET.get("closed-remittances-page", 1), per_page=10)
@ -281,8 +281,6 @@ class RemittanceUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context["table"] = RemittanceTable(data=Remittance.objects.filter(
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all())
data = SpecialTransaction.objects.filter(specialtransactionproxy__remittance=self.object).filter( data = SpecialTransaction.objects.filter(specialtransactionproxy__remittance=self.object).filter(
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all() PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all()
context["special_transactions"] = SpecialTransactionTable( context["special_transactions"] = SpecialTransactionTable(

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-08-05 16:18+0200\n" "POT-Creation-Date: 2020-08-05 16:49+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -187,13 +187,13 @@ msgid "Type"
msgstr "" msgstr ""
#: apps/activity/tables.py:77 apps/member/forms.py:103 #: apps/activity/tables.py:77 apps/member/forms.py:103
#: apps/registration/forms.py:70 apps/treasury/forms.py:120 #: apps/registration/forms.py:70 apps/treasury/forms.py:126
#: apps/wei/forms/registration.py:95 #: apps/wei/forms/registration.py:95
msgid "Last name" msgid "Last name"
msgstr "" msgstr ""
#: apps/activity/tables.py:79 apps/member/forms.py:108 #: apps/activity/tables.py:79 apps/member/forms.py:108
#: apps/registration/forms.py:75 apps/treasury/forms.py:122 #: apps/registration/forms.py:75 apps/treasury/forms.py:128
#: apps/wei/forms/registration.py:100 templates/note/transaction_form.html:129 #: apps/wei/forms/registration.py:100 templates/note/transaction_form.html:129
msgid "First name" msgid "First name"
msgstr "" msgstr ""
@ -347,7 +347,7 @@ msgid "Credit amount"
msgstr "" msgstr ""
#: apps/member/forms.py:113 apps/registration/forms.py:80 #: apps/member/forms.py:113 apps/registration/forms.py:80
#: apps/treasury/forms.py:124 apps/wei/forms/registration.py:105 #: apps/treasury/forms.py:130 apps/wei/forms/registration.py:105
#: templates/note/transaction_form.html:135 #: templates/note/transaction_form.html:135
msgid "Bank" msgid "Bank"
msgstr "" msgstr ""
@ -687,7 +687,7 @@ msgstr ""
msgid "Reason" msgid "Reason"
msgstr "" msgstr ""
#: apps/note/forms.py:87 apps/treasury/tables.py:117 #: apps/note/forms.py:87 apps/treasury/tables.py:119
msgid "Valid" msgid "Valid"
msgstr "" msgstr ""
@ -1169,7 +1169,7 @@ msgstr ""
msgid "Treasury" msgid "Treasury"
msgstr "" msgstr ""
#: apps/treasury/forms.py:84 apps/treasury/forms.py:132 #: apps/treasury/forms.py:84 apps/treasury/forms.py:138
#: templates/activity/activity_form.html:9 #: templates/activity/activity_form.html:9
#: templates/activity/activity_invite.html:8 #: templates/activity/activity_invite.html:8
#: templates/django_filters/rest_framework/form.html:5 #: templates/django_filters/rest_framework/form.html:5
@ -1193,8 +1193,20 @@ msgstr ""
msgid "You can't change the type of the remittance." msgid "You can't change the type of the remittance."
msgstr "" msgstr ""
#: apps/treasury/forms.py:126 apps/treasury/tables.py:47 #: apps/treasury/forms.py:120 apps/treasury/models.py:207
#: apps/treasury/tables.py:113 templates/note/transaction_form.html:97 #: apps/treasury/tables.py:77 apps/treasury/tables.py:85
#: templates/treasury/invoice_list.html:13
#: templates/treasury/remittance_list.html:13
#: templates/treasury/sogecredit_list.html:13
msgid "Remittance"
msgstr ""
#: apps/treasury/forms.py:121
msgid "No attached remittance"
msgstr ""
#: apps/treasury/forms.py:132 apps/treasury/tables.py:47
#: apps/treasury/tables.py:115 templates/note/transaction_form.html:97
#: templates/treasury/remittance_form.html:18 #: templates/treasury/remittance_form.html:18
msgid "Amount" msgid "Amount"
msgstr "" msgstr ""
@ -1291,13 +1303,6 @@ msgstr ""
msgid "Remittance #{:d}: {}" msgid "Remittance #{:d}: {}"
msgstr "" msgstr ""
#: apps/treasury/models.py:207 apps/treasury/tables.py:76
#: apps/treasury/tables.py:84 templates/treasury/invoice_list.html:13
#: templates/treasury/remittance_list.html:13
#: templates/treasury/sogecredit_list.html:13
msgid "Remittance"
msgstr ""
#: apps/treasury/models.py:211 #: apps/treasury/models.py:211
msgid "special transaction proxy" msgid "special transaction proxy"
msgstr "" msgstr ""
@ -1342,19 +1347,19 @@ msgstr ""
msgid "View" msgid "View"
msgstr "" msgstr ""
#: apps/treasury/tables.py:78 #: apps/treasury/tables.py:79
msgid "Add" msgid "Add"
msgstr "" msgstr ""
#: apps/treasury/tables.py:86 #: apps/treasury/tables.py:87
msgid "Remove" msgid "Remove"
msgstr "" msgstr ""
#: apps/treasury/tables.py:124 #: apps/treasury/tables.py:126
msgid "Yes" msgid "Yes"
msgstr "" msgstr ""
#: apps/treasury/tables.py:124 #: apps/treasury/tables.py:126
msgid "No" msgid "No"
msgstr "" msgstr ""
@ -2147,16 +2152,16 @@ msgid ""
"activate your account." "activate your account."
msgstr "" msgstr ""
#: templates/registration/email_validation_email_sent.html:4 #: templates/registration/email_validation_email_sent.html:5
msgid "Account activation" msgid "Account activation"
msgstr "" msgstr ""
#: templates/registration/email_validation_email_sent.html:7 #: templates/registration/email_validation_email_sent.html:8
msgid "" msgid ""
"An email has been sent. Please click on the link to activate your account." "An email has been sent. Please click on the link to activate your account."
msgstr "" msgstr ""
#: templates/registration/email_validation_email_sent.html:11 #: templates/registration/email_validation_email_sent.html:12
msgid "" msgid ""
"You must also go to the Kfet to pay your membership. The WEI registration " "You must also go to the Kfet to pay your membership. The WEI registration "
"includes the BDE membership." "includes the BDE membership."

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-08-05 16:18+0200\n" "POT-Creation-Date: 2020-08-05 16:49+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -188,13 +188,13 @@ msgid "Type"
msgstr "Type" msgstr "Type"
#: apps/activity/tables.py:77 apps/member/forms.py:103 #: apps/activity/tables.py:77 apps/member/forms.py:103
#: apps/registration/forms.py:70 apps/treasury/forms.py:120 #: apps/registration/forms.py:70 apps/treasury/forms.py:126
#: apps/wei/forms/registration.py:95 #: apps/wei/forms/registration.py:95
msgid "Last name" msgid "Last name"
msgstr "Nom de famille" msgstr "Nom de famille"
#: apps/activity/tables.py:79 apps/member/forms.py:108 #: apps/activity/tables.py:79 apps/member/forms.py:108
#: apps/registration/forms.py:75 apps/treasury/forms.py:122 #: apps/registration/forms.py:75 apps/treasury/forms.py:128
#: apps/wei/forms/registration.py:100 templates/note/transaction_form.html:129 #: apps/wei/forms/registration.py:100 templates/note/transaction_form.html:129
msgid "First name" msgid "First name"
msgstr "Prénom" msgstr "Prénom"
@ -348,7 +348,7 @@ msgid "Credit amount"
msgstr "Montant à créditer" msgstr "Montant à créditer"
#: apps/member/forms.py:113 apps/registration/forms.py:80 #: apps/member/forms.py:113 apps/registration/forms.py:80
#: apps/treasury/forms.py:124 apps/wei/forms/registration.py:105 #: apps/treasury/forms.py:130 apps/wei/forms/registration.py:105
#: templates/note/transaction_form.html:135 #: templates/note/transaction_form.html:135
msgid "Bank" msgid "Bank"
msgstr "Banque" msgstr "Banque"
@ -694,7 +694,7 @@ msgstr "Destination"
msgid "Reason" msgid "Reason"
msgstr "Raison" msgstr "Raison"
#: apps/note/forms.py:87 apps/treasury/tables.py:117 #: apps/note/forms.py:87 apps/treasury/tables.py:119
msgid "Valid" msgid "Valid"
msgstr "Valide" msgstr "Valide"
@ -1198,7 +1198,7 @@ msgstr "Invalider l'inscription"
msgid "Treasury" msgid "Treasury"
msgstr "Trésorerie" msgstr "Trésorerie"
#: apps/treasury/forms.py:84 apps/treasury/forms.py:132 #: apps/treasury/forms.py:84 apps/treasury/forms.py:138
#: templates/activity/activity_form.html:9 #: templates/activity/activity_form.html:9
#: templates/activity/activity_invite.html:8 #: templates/activity/activity_invite.html:8
#: templates/django_filters/rest_framework/form.html:5 #: templates/django_filters/rest_framework/form.html:5
@ -1222,8 +1222,20 @@ msgstr "La remise est déjà fermée."
msgid "You can't change the type of the remittance." msgid "You can't change the type of the remittance."
msgstr "Vous ne pouvez pas changer le type de la remise." msgstr "Vous ne pouvez pas changer le type de la remise."
#: apps/treasury/forms.py:126 apps/treasury/tables.py:47 #: apps/treasury/forms.py:120 apps/treasury/models.py:207
#: apps/treasury/tables.py:113 templates/note/transaction_form.html:97 #: apps/treasury/tables.py:77 apps/treasury/tables.py:85
#: templates/treasury/invoice_list.html:13
#: templates/treasury/remittance_list.html:13
#: templates/treasury/sogecredit_list.html:13
msgid "Remittance"
msgstr "Remise"
#: apps/treasury/forms.py:121
msgid "No attached remittance"
msgstr "Pas de remise associée"
#: apps/treasury/forms.py:132 apps/treasury/tables.py:47
#: apps/treasury/tables.py:115 templates/note/transaction_form.html:97
#: templates/treasury/remittance_form.html:18 #: templates/treasury/remittance_form.html:18
msgid "Amount" msgid "Amount"
msgstr "Montant" msgstr "Montant"
@ -1320,13 +1332,6 @@ msgstr "remises"
msgid "Remittance #{:d}: {}" msgid "Remittance #{:d}: {}"
msgstr "Remise n°{:d} : {}" msgstr "Remise n°{:d} : {}"
#: apps/treasury/models.py:207 apps/treasury/tables.py:76
#: apps/treasury/tables.py:84 templates/treasury/invoice_list.html:13
#: templates/treasury/remittance_list.html:13
#: templates/treasury/sogecredit_list.html:13
msgid "Remittance"
msgstr "Remise"
#: apps/treasury/models.py:211 #: apps/treasury/models.py:211
msgid "special transaction proxy" msgid "special transaction proxy"
msgstr "Proxy de transaction spéciale" msgstr "Proxy de transaction spéciale"
@ -1373,19 +1378,19 @@ msgstr "Nombre de transactions"
msgid "View" msgid "View"
msgstr "Voir" msgstr "Voir"
#: apps/treasury/tables.py:78 #: apps/treasury/tables.py:79
msgid "Add" msgid "Add"
msgstr "Ajouter" msgstr "Ajouter"
#: apps/treasury/tables.py:86 #: apps/treasury/tables.py:87
msgid "Remove" msgid "Remove"
msgstr "supprimer" msgstr "supprimer"
#: apps/treasury/tables.py:124 #: apps/treasury/tables.py:126
msgid "Yes" msgid "Yes"
msgstr "Oui" msgstr "Oui"
#: apps/treasury/tables.py:124 #: apps/treasury/tables.py:126
msgid "No" msgid "No"
msgstr "Non" msgstr "Non"
@ -2218,18 +2223,18 @@ msgstr ""
"Le lien est invalide. Le jeton a sans doute expiré. Merci de nous contacter " "Le lien est invalide. Le jeton a sans doute expiré. Merci de nous contacter "
"pour activer votre compte." "pour activer votre compte."
#: templates/registration/email_validation_email_sent.html:4 #: templates/registration/email_validation_email_sent.html:5
msgid "Account activation" msgid "Account activation"
msgstr "Activation du compte" msgstr "Activation du compte"
#: templates/registration/email_validation_email_sent.html:7 #: templates/registration/email_validation_email_sent.html:8
msgid "" msgid ""
"An email has been sent. Please click on the link to activate your account." "An email has been sent. Please click on the link to activate your account."
msgstr "" msgstr ""
"Un email vient de vous être envoyé. Merci de cliquer sur le lien de " "Un email vient de vous être envoyé. Merci de cliquer sur le lien de "
"validation pour activer votre compte." "validation pour activer votre compte."
#: templates/registration/email_validation_email_sent.html:11 #: templates/registration/email_validation_email_sent.html:12
msgid "" msgid ""
"You must also go to the Kfet to pay your membership. The WEI registration " "You must also go to the Kfet to pay your membership. The WEI registration "
"includes the BDE membership." "includes the BDE membership."

View File

@ -1,5 +1,5 @@
<div class="input-group"> <div class="input-group">
<input class="form-control mx-auto d-block" type="number" min="0" step="0.01" <input class="form-control mx-auto d-block" type="number" {% if not widget.attrs.negative %}min="0"{% endif %} step="0.01"
{% if widget.value != None and widget.value != "" %}value="{{ widget.value }}"{% endif %} {% if widget.value != None and widget.value != "" %}value="{{ widget.value }}"{% endif %}
name="{{ widget.name }}" name="{{ widget.name }}"
{% for name, value in widget.attrs.items %} {% for name, value in widget.attrs.items %}