From eadb52146a4e6a16193ae2eff0349f10f5b4bfc5 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Tue, 10 Jul 2018 16:46:49 +0200 Subject: [PATCH 1/4] =?UTF-8?q?Validation=20des=20factures=20=C3=A0=20la?= =?UTF-8?q?=20recharge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cotisations/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cotisations/views.py b/cotisations/views.py index aa60aa8b..9be079f5 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -677,9 +677,9 @@ def credit_solde(request, user, **_kwargs): """ refill_form = RechargeForm(request.POST or None, user=request.user) if refill_form.is_valid(): - invoice = Facture(user=request.user) + invoice = Facture(user=user) invoice.paiement = refill_form.cleaned_data['payment'] - invoice.valid = False + invoice.valid = True invoice.save() Vente.objects.create( facture=invoice, From 35616c89d8c71b629818a20eaa78d6da29134c63 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Tue, 10 Jul 2018 16:50:48 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Affiche=20le=20message=20pour=20le=20bon=20?= =?UTF-8?q?utilisateur=20=C3=A0=20la=20validation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cotisations/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cotisations/models.py b/cotisations/models.py index 37d030ea..7bcdbc00 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -695,8 +695,8 @@ class Paiement(RevMixin, AclMixin, models.Model): request, _("The cotisation of %(member_name)s has been \ extended to %(end_date)s.") % { - 'member_name': request.user.pseudo, - 'end_date': request.user.end_adhesion() + 'member_name': invoice.user.pseudo, + 'end_date': invoice.user.end_adhesion() } ) # Else, only tell the invoice was created From 017f2adc22400de193c818b224c5ab8e95492a7e Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Tue, 10 Jul 2018 18:06:58 +0200 Subject: [PATCH 3/4] Fix les erreurs d'affichage de solde --- .../templates/cotisations/facture.html | 19 ++- .../templates/cotisations/new_facture.html | 148 ------------------ cotisations/views.py | 13 +- 3 files changed, 22 insertions(+), 158 deletions(-) delete mode 100644 cotisations/templates/cotisations/new_facture.html diff --git a/cotisations/templates/cotisations/facture.html b/cotisations/templates/cotisations/facture.html index 081f3f51..fbbb0f7d 100644 --- a/cotisations/templates/cotisations/facture.html +++ b/cotisations/templates/cotisations/facture.html @@ -36,12 +36,22 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endif %} {% if title %}

{{title}}

+{% else %} +

{% trans "New invoice" %}

{% endif %} -{% if balance %} -

{% trans "Current balance :" %}{{balance}}€

+{% if balance is not None %} +

+ {% trans "Current balance :" %} {{ balance }} € +

{% endif %} +
{% csrf_token %} + {% bootstrap_form factureform %} + {% if payment_method %} + {% bootstrap_form payment_method %} +
+ {% endif %} {% if articlesformset %}

{% trans "Invoice's articles" %}

@@ -64,11 +74,6 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endblocktrans %}

{% endif %} - {% bootstrap_form factureform %} - {% if payment_method %} - {% bootstrap_form payment_method %} -
- {% endif %} {% bootstrap_button action_name button_type='submit' icon='star' %} diff --git a/cotisations/templates/cotisations/new_facture.html b/cotisations/templates/cotisations/new_facture.html deleted file mode 100644 index ddb1ece8..00000000 --- a/cotisations/templates/cotisations/new_facture.html +++ /dev/null @@ -1,148 +0,0 @@ -{% extends "cotisations/sidebar.html" %} -{% comment %} -Re2o est un logiciel d'administration développé initiallement au rezometz. Il -se veut agnostique au réseau considéré, de manière à être installable en -quelques clics. - -Copyright © 2017 Gabriel Détraz -Copyright © 2017 Goulven Kermarec -Copyright © 2017 Augustin Lemesle - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -{% endcomment %} - -{% load bootstrap3 %} -{% load staticfiles%} -{% load i18n %} - -{% block title %}{% trans "Invoices creation and edition" %}{% endblock %} - -{% block content %} -{% bootstrap_form_errors factureform %} - -
- {% csrf_token %} -

{% trans "New invoice" %}

- {% if user.solde %} -

- {% blocktrans %} - User's balance : {{ user.solde }} € - {% endblocktrans %} -

- {% endif %} - {% bootstrap_form factureform %} - {{ venteform.management_form }} -

{% trans "Invoice's articles" %}

-
- {% for form in venteform.forms %} -
- {% trans "Article" %} :   - {% bootstrap_form form label_class='sr-only' %} -   - -
- {% endfor %} -
- -

- {% blocktrans %} - Total price : 0,00 € - {% endblocktrans %} -

- {% trans "Create" as tr_create %} - {% bootstrap_button tr_create button_type='submit' icon='star' %} -
- - - -{% endblock %} diff --git a/cotisations/views.py b/cotisations/views.py index 9be079f5..c1a8d68f 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -143,13 +143,20 @@ def new_facture(request, user, userid): request, _("You need to choose at least one article.") ) + p = Paiement.objects.filter(is_balance=True) + if len(p) and p[0].can_use_payment(request.user): + balance = user.solde + else: + balance = None return form( { 'factureform': invoice_form, - 'venteform': article_formset, - 'articlelist': article_list + 'articlesformset': article_formset, + 'articlelist': article_list, + 'balance': balance, + 'action_name': _('Create'), }, - 'cotisations/new_facture.html', request + 'cotisations/facture.html', request ) From ac90d4d7ee594c5cf108fc8ad52ac2994cde5213 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Tue, 10 Jul 2018 18:38:05 +0200 Subject: [PATCH 4/4] =?UTF-8?q?Fix=20de=20l'=C3=A9dition=20de=20factures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cotisations/forms.py | 42 ++++++++++++++---------------------------- cotisations/views.py | 12 ++++++------ 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/cotisations/forms.py b/cotisations/forms.py index 02ee3e3c..e1dd9e28 100644 --- a/cotisations/forms.py +++ b/cotisations/forms.py @@ -49,28 +49,34 @@ from .models import Article, Paiement, Facture, Banque from .payment_methods import balance -class NewFactureForm(FormRevMixin, ModelForm): +class FactureForm(FieldPermissionFormMixin, FormRevMixin, ModelForm): """ - Form used to create a new invoice by using a payment method, a bank and a - cheque number. + Form used to manage and create an invoice and its fields. """ - def __init__(self, *args, **kwargs): - user = kwargs.pop('user') + def __init__(self, *args, creation=False, **kwargs): + user = kwargs['user'] prefix = kwargs.pop('prefix', self.Meta.model.__name__) - super(NewFactureForm, self).__init__(*args, prefix=prefix, **kwargs) + super(FactureForm, self).__init__(*args, prefix=prefix, **kwargs) self.fields['paiement'].empty_label = \ _("Select a payment method") self.fields['paiement'].queryset = Paiement.objects.filter( pk__in=map(lambda x: x.pk, Paiement.find_allowed_payments(user)) ) + if not creation: + self.fields['user'].label = _("Member") + self.fields['user'].empty_label = \ + _("Select the proprietary member") + self.fields['valid'].label = _("Validated invoice") + else: + self.fields = {'paiement': self.fields['paiement']} class Meta: model = Facture - fields = ['paiement'] + fields = '__all__' def clean(self): - cleaned_data = super(NewFactureForm, self).clean() + cleaned_data = super(FactureForm, self).clean() paiement = cleaned_data.get('paiement') if not paiement: raise forms.ValidationError( @@ -151,26 +157,6 @@ class NewFactureFormPdf(Form): ) -# TODO : change Facture to Invoice -class EditFactureForm(FieldPermissionFormMixin, NewFactureForm): - """ - Form used to edit an invoice and its fields : payment method, bank, - user associated, ... - """ - class Meta(NewFactureForm.Meta): - # TODO : change Facture to Invoice - model = Facture - fields = '__all__' - - def __init__(self, *args, **kwargs): - # TODO : change Facture to Invoice - super(EditFactureForm, self).__init__(*args, **kwargs) - self.fields['user'].label = _("Member") - self.fields['user'].empty_label = \ - _("Select the proprietary member") - self.fields['valid'].label = _("Validated invoice") - - class ArticleForm(FormRevMixin, ModelForm): """ Form used to create an article. diff --git a/cotisations/views.py b/cotisations/views.py index c1a8d68f..13c8b461 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -60,8 +60,7 @@ from re2o.acl import ( from preferences.models import AssoOption, GeneralOption from .models import Facture, Article, Vente, Paiement, Banque from .forms import ( - NewFactureForm, - EditFactureForm, + FactureForm, ArticleForm, DelArticleForm, PaiementForm, @@ -84,7 +83,7 @@ def new_facture(request, user, userid): """ View called to create a new invoice. Currently, Send the list of available articles for the user along with - a formset of a new invoice (based on the `:forms:NewFactureForm()` form. + a formset of a new invoice (based on the `:forms:FactureForm()` form. A bit of JS is used in the template to add articles in a fancier way. If everything is correct, save each one of the articles, save the purchase object associated and finally the newly created invoice. @@ -95,10 +94,11 @@ def new_facture(request, user, userid): Q(type_user='All') | Q(type_user=request.user.class_name) ) # Building the invoice form and the article formset - invoice_form = NewFactureForm( + invoice_form = FactureForm( request.POST or None, instance=invoice, - user=request.user + user=request.user, + creation=True ) if request.user.is_class_club: @@ -278,7 +278,7 @@ def edit_facture(request, facture, **_kwargs): can be set as desired. This is also the view used to invalidate an invoice. """ - invoice_form = EditFactureForm( + invoice_form = FactureForm( request.POST or None, instance=facture, user=request.user