From b0398e59b8d218c4bc434d931ee2168ab4abbaae Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 5 Aug 2020 18:04:01 +0200 Subject: [PATCH] :bug: Fix treasury --- apps/treasury/forms.py | 56 +++++++++++++++----------------- apps/treasury/models.py | 2 +- apps/treasury/tables.py | 4 ++- apps/treasury/views.py | 4 +-- locale/de/LC_MESSAGES/django.po | 49 +++++++++++++++------------- locale/fr/LC_MESSAGES/django.po | 49 +++++++++++++++------------- templates/note/amount_input.html | 2 +- 7 files changed, 86 insertions(+), 80 deletions(-) diff --git a/apps/treasury/forms.py b/apps/treasury/forms.py index 4c761ef2..7ff16c8f 100644 --- a/apps/treasury/forms.py +++ b/apps/treasury/forms.py @@ -1,11 +1,10 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -import datetime - from crispy_forms.helper import FormHelper from crispy_forms.layout import Submit from django import forms +from django.utils import timezone from django.utils.translation import gettext_lazy as _ 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 date = forms.DateField( - initial=datetime.date.today, - widget=DatePickerInput() + initial=timezone.now, + widget=DatePickerInput(), ) def clean_date(self): self.instance.date = self.data.get("date") + return self.instance.date class Meta: model = Invoice @@ -36,7 +36,11 @@ class ProductForm(forms.ModelForm): model = Product fields = '__all__' widgets = { - "amount": AmountInput() + "amount": AmountInput( + attrs={ + "negative": True, + } + ) } @@ -115,6 +119,12 @@ class LinkTransactionToRemittanceForm(forms.ModelForm): """ 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 last_name = forms.CharField(label=_("Last name")) @@ -123,7 +133,7 @@ class LinkTransactionToRemittanceForm(forms.ModelForm): 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): super().__init__(*args, **kwargs) @@ -133,33 +143,19 @@ class LinkTransactionToRemittanceForm(forms.ModelForm): self.fields["remittance"].queryset = Remittance.objects.filter(closed=False) - def clean_last_name(self): - """ - Replace the first name in the information of the transaction. - """ - self.instance.transaction.last_name = self.data.get("last_name") - self.instance.transaction.clean() + def clean(self): + cleaned_data = super().clean() + self.instance.transaction.last_name = cleaned_data["last_name"] + self.instance.transaction.first_name = cleaned_data["first_name"] + self.instance.transaction.bank = cleaned_data["bank"] + 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.clean() - - 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() + self.instance.transaction.save() + return super().save(commit) class Meta: model = SpecialTransactionProxy diff --git a/apps/treasury/models.py b/apps/treasury/models.py index 6cfb55c1..90366e7e 100644 --- a/apps/treasury/models.py +++ b/apps/treasury/models.py @@ -82,7 +82,7 @@ class Product(models.Model): verbose_name=_("Designation"), ) - quantity = models.PositiveIntegerField( + quantity = models.IntegerField( verbose_name=_("Quantity") ) diff --git a/apps/treasury/tables.py b/apps/treasury/tables.py index 9f4e43e6..c7bdb6eb 100644 --- a/apps/treasury/tables.py +++ b/apps/treasury/tables.py @@ -64,6 +64,7 @@ class RemittanceTable(tables.Table): model = Remittance template_name = 'django_tables2/bootstrap4.html' fields = ('id', 'date', 'remittance_type', 'comment', 'count', 'amount', 'view',) + order_by = ('-date',) class SpecialTransactionTable(tables.Table): @@ -100,7 +101,8 @@ class SpecialTransactionTable(tables.Table): } model = SpecialTransaction 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): diff --git a/apps/treasury/views.py b/apps/treasury/views.py index 088345b8..2fbe4777 100644 --- a/apps/treasury/views.py +++ b/apps/treasury/views.py @@ -238,7 +238,7 @@ class RemittanceListView(LoginRequiredMixin, TemplateView): closed_remittances = RemittanceTable( 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-", ) 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): 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( PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all() context["special_transactions"] = SpecialTransactionTable( diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index f75fc004..80397341 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\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" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -187,13 +187,13 @@ msgid "Type" msgstr "" #: 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 msgid "Last name" msgstr "" #: 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 msgid "First name" msgstr "" @@ -347,7 +347,7 @@ msgid "Credit amount" msgstr "" #: 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 msgid "Bank" msgstr "" @@ -687,7 +687,7 @@ msgstr "" msgid "Reason" msgstr "" -#: apps/note/forms.py:87 apps/treasury/tables.py:117 +#: apps/note/forms.py:87 apps/treasury/tables.py:119 msgid "Valid" msgstr "" @@ -1169,7 +1169,7 @@ msgstr "" msgid "Treasury" 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_invite.html:8 #: templates/django_filters/rest_framework/form.html:5 @@ -1193,8 +1193,20 @@ msgstr "" msgid "You can't change the type of the remittance." msgstr "" -#: apps/treasury/forms.py:126 apps/treasury/tables.py:47 -#: apps/treasury/tables.py:113 templates/note/transaction_form.html:97 +#: apps/treasury/forms.py:120 apps/treasury/models.py:207 +#: 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 msgid "Amount" msgstr "" @@ -1291,13 +1303,6 @@ msgstr "" msgid "Remittance #{:d}: {}" 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 msgid "special transaction proxy" msgstr "" @@ -1342,19 +1347,19 @@ msgstr "" msgid "View" msgstr "" -#: apps/treasury/tables.py:78 +#: apps/treasury/tables.py:79 msgid "Add" msgstr "" -#: apps/treasury/tables.py:86 +#: apps/treasury/tables.py:87 msgid "Remove" msgstr "" -#: apps/treasury/tables.py:124 +#: apps/treasury/tables.py:126 msgid "Yes" msgstr "" -#: apps/treasury/tables.py:124 +#: apps/treasury/tables.py:126 msgid "No" msgstr "" @@ -2147,16 +2152,16 @@ msgid "" "activate your account." msgstr "" -#: templates/registration/email_validation_email_sent.html:4 +#: templates/registration/email_validation_email_sent.html:5 msgid "Account activation" msgstr "" -#: templates/registration/email_validation_email_sent.html:7 +#: templates/registration/email_validation_email_sent.html:8 msgid "" "An email has been sent. Please click on the link to activate your account." msgstr "" -#: templates/registration/email_validation_email_sent.html:11 +#: templates/registration/email_validation_email_sent.html:12 msgid "" "You must also go to the Kfet to pay your membership. The WEI registration " "includes the BDE membership." diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index e4d860c3..b87eaa1d 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\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" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -188,13 +188,13 @@ msgid "Type" msgstr "Type" #: 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 msgid "Last name" msgstr "Nom de famille" #: 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 msgid "First name" msgstr "Prénom" @@ -348,7 +348,7 @@ msgid "Credit amount" msgstr "Montant à créditer" #: 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 msgid "Bank" msgstr "Banque" @@ -694,7 +694,7 @@ msgstr "Destination" msgid "Reason" msgstr "Raison" -#: apps/note/forms.py:87 apps/treasury/tables.py:117 +#: apps/note/forms.py:87 apps/treasury/tables.py:119 msgid "Valid" msgstr "Valide" @@ -1198,7 +1198,7 @@ msgstr "Invalider l'inscription" msgid "Treasury" 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_invite.html:8 #: 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." msgstr "Vous ne pouvez pas changer le type de la remise." -#: apps/treasury/forms.py:126 apps/treasury/tables.py:47 -#: apps/treasury/tables.py:113 templates/note/transaction_form.html:97 +#: apps/treasury/forms.py:120 apps/treasury/models.py:207 +#: 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 msgid "Amount" msgstr "Montant" @@ -1320,13 +1332,6 @@ msgstr "remises" msgid "Remittance #{: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 msgid "special transaction proxy" msgstr "Proxy de transaction spéciale" @@ -1373,19 +1378,19 @@ msgstr "Nombre de transactions" msgid "View" msgstr "Voir" -#: apps/treasury/tables.py:78 +#: apps/treasury/tables.py:79 msgid "Add" msgstr "Ajouter" -#: apps/treasury/tables.py:86 +#: apps/treasury/tables.py:87 msgid "Remove" msgstr "supprimer" -#: apps/treasury/tables.py:124 +#: apps/treasury/tables.py:126 msgid "Yes" msgstr "Oui" -#: apps/treasury/tables.py:124 +#: apps/treasury/tables.py:126 msgid "No" msgstr "Non" @@ -2218,18 +2223,18 @@ msgstr "" "Le lien est invalide. Le jeton a sans doute expiré. Merci de nous contacter " "pour activer votre compte." -#: templates/registration/email_validation_email_sent.html:4 +#: templates/registration/email_validation_email_sent.html:5 msgid "Account activation" msgstr "Activation du compte" -#: templates/registration/email_validation_email_sent.html:7 +#: templates/registration/email_validation_email_sent.html:8 msgid "" "An email has been sent. Please click on the link to activate your account." msgstr "" "Un email vient de vous être envoyé. Merci de cliquer sur le lien de " "validation pour activer votre compte." -#: templates/registration/email_validation_email_sent.html:11 +#: templates/registration/email_validation_email_sent.html:12 msgid "" "You must also go to the Kfet to pay your membership. The WEI registration " "includes the BDE membership." diff --git a/templates/note/amount_input.html b/templates/note/amount_input.html index cd8cd201..f4515234 100644 --- a/templates/note/amount_input.html +++ b/templates/note/amount_input.html @@ -1,5 +1,5 @@
-