mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 19:33:11 +00:00
Utilise un ModelForm pour les données de chèque + doc
This commit is contained in:
parent
3f2de5739c
commit
2845c49ac1
2 changed files with 36 additions and 31 deletions
|
@ -232,7 +232,6 @@ class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
_("You don't have the right to create an invoice.")
|
_("You don't have the right to create an invoice.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Facture, self).__init__(*args, **kwargs)
|
super(Facture, self).__init__(*args, **kwargs)
|
||||||
self.field_permissions = {
|
self.field_permissions = {
|
||||||
|
@ -632,12 +631,19 @@ class Paiement(RevMixin, AclMixin, models.Model):
|
||||||
)
|
)
|
||||||
super(Paiement, self).save(*args, **kwargs)
|
super(Paiement, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def end_payment(self, invoice, request):
|
def end_payment(self, invoice, request, use_payment_method=True):
|
||||||
"""
|
"""
|
||||||
The general way of ending a payment. You may redefine this method for custom
|
The general way of ending a payment.
|
||||||
payment methods. Must return a HttpResponse-like object.
|
|
||||||
|
:param invoice: The invoice being created.
|
||||||
|
:param request: Request sended by the user.
|
||||||
|
:param use_payment_method: If `self` has an attribute `payment_method`,
|
||||||
|
returns the result of
|
||||||
|
`self.payment_method.end_payment(invoice, request)`
|
||||||
|
|
||||||
|
:returns: An `HttpResponse`-like object.
|
||||||
"""
|
"""
|
||||||
if hasattr(self, 'payment_method'):
|
if hasattr(self, 'payment_method') and use_payment_method:
|
||||||
return self.payment_method.end_payment(invoice, request)
|
return self.payment_method.end_payment(invoice, request)
|
||||||
|
|
||||||
# In case a cotisation was bought, inform the user, the
|
# In case a cotisation was bought, inform the user, the
|
||||||
|
|
|
@ -12,7 +12,7 @@ from django.utils.translation import ugettext as _
|
||||||
from cotisations.models import Facture as Invoice
|
from cotisations.models import Facture as Invoice
|
||||||
|
|
||||||
from .models import ChequePayment
|
from .models import ChequePayment
|
||||||
from .forms import ChequeForm
|
from .forms import InvoiceForm
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -28,16 +28,15 @@ def cheque(request, invoice_pk):
|
||||||
'users:profil',
|
'users:profil',
|
||||||
kwargs={'userid': request.user.pk}
|
kwargs={'userid': request.user.pk}
|
||||||
))
|
))
|
||||||
form = ChequeForm(request.POST or None)
|
form = InvoiceForm(request.POST or None, instance=invoice)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
invoice.banque = form.cleaned_data['bank']
|
form.instance.valid = True
|
||||||
invoice.cheque = form.cleaned_data['number']
|
form.save()
|
||||||
invoice.valid = True
|
return form.instance.paiement.end_payment(
|
||||||
invoice.save()
|
form.instance,
|
||||||
return redirect(reverse(
|
request,
|
||||||
'users:profil',
|
use_payment_method=False
|
||||||
kwargs={'userid': request.user.pk}
|
)
|
||||||
))
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
'cotisations/payment_form.html',
|
'cotisations/payment_form.html',
|
||||||
|
|
Loading…
Reference in a new issue