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/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 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 %}
+ {% trans "Current balance :" %} {{ balance }} € +
{% endif %} +