Commit ee865955 authored by Hugo LEVY-FALK's avatar Hugo LEVY-FALK

Fix de l'édition de factures

parent f87b85d4
...@@ -49,28 +49,34 @@ from .models import Article, Paiement, Facture, Banque ...@@ -49,28 +49,34 @@ from .models import Article, Paiement, Facture, Banque
from .payment_methods import balance 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 Form used to manage and create an invoice and its fields.
cheque number.
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, creation=False, **kwargs):
user = kwargs.pop('user') user = kwargs['user']
prefix = kwargs.pop('prefix', self.Meta.model.__name__) 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 = \ self.fields['paiement'].empty_label = \
_("Select a payment method") _("Select a payment method")
self.fields['paiement'].queryset = Paiement.objects.filter( self.fields['paiement'].queryset = Paiement.objects.filter(
pk__in=map(lambda x: x.pk, Paiement.find_allowed_payments(user)) 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: class Meta:
model = Facture model = Facture
fields = ['paiement'] fields = '__all__'
def clean(self): def clean(self):
cleaned_data = super(NewFactureForm, self).clean() cleaned_data = super(FactureForm, self).clean()
paiement = cleaned_data.get('paiement') paiement = cleaned_data.get('paiement')
if not paiement: if not paiement:
raise forms.ValidationError( raise forms.ValidationError(
...@@ -151,26 +157,6 @@ class NewFactureFormPdf(Form): ...@@ -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): class ArticleForm(FormRevMixin, ModelForm):
""" """
Form used to create an article. Form used to create an article.
......
...@@ -60,8 +60,7 @@ from re2o.acl import ( ...@@ -60,8 +60,7 @@ from re2o.acl import (
from preferences.models import AssoOption, GeneralOption from preferences.models import AssoOption, GeneralOption
from .models import Facture, Article, Vente, Paiement, Banque from .models import Facture, Article, Vente, Paiement, Banque
from .forms import ( from .forms import (
NewFactureForm, FactureForm,
EditFactureForm,
ArticleForm, ArticleForm,
DelArticleForm, DelArticleForm,
PaiementForm, PaiementForm,
...@@ -84,7 +83,7 @@ def new_facture(request, user, userid): ...@@ -84,7 +83,7 @@ def new_facture(request, user, userid):
""" """
View called to create a new invoice. View called to create a new invoice.
Currently, Send the list of available articles for the user along with 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. 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 If everything is correct, save each one of the articles, save the
purchase object associated and finally the newly created invoice. purchase object associated and finally the newly created invoice.
...@@ -95,10 +94,11 @@ def new_facture(request, user, userid): ...@@ -95,10 +94,11 @@ def new_facture(request, user, userid):
Q(type_user='All') | Q(type_user=request.user.class_name) Q(type_user='All') | Q(type_user=request.user.class_name)
) )
# Building the invoice form and the article formset # Building the invoice form and the article formset
invoice_form = NewFactureForm( invoice_form = FactureForm(
request.POST or None, request.POST or None,
instance=invoice, instance=invoice,
user=request.user user=request.user,
creation=True
) )
if request.user.is_class_club: if request.user.is_class_club:
...@@ -278,7 +278,7 @@ def edit_facture(request, facture, **_kwargs): ...@@ -278,7 +278,7 @@ def edit_facture(request, facture, **_kwargs):
can be set as desired. This is also the view used to invalidate can be set as desired. This is also the view used to invalidate
an invoice. an invoice.
""" """
invoice_form = EditFactureForm( invoice_form = FactureForm(
request.POST or None, request.POST or None,
instance=facture, instance=facture,
user=request.user user=request.user
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment