2018-07-07 22:01:06 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
2020-11-23 16:06:37 +00:00
|
|
|
# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il
|
2018-07-07 22:01:06 +00:00
|
|
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
|
|
# quelques clics.
|
|
|
|
#
|
|
|
|
# Copyright © 2018 Hugo Levy-Falk
|
|
|
|
#
|
|
|
|
# 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.
|
2018-06-21 18:03:46 +00:00
|
|
|
"""Payment
|
|
|
|
|
|
|
|
Here are defined some views dedicated to cheque payement.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django.contrib import messages
|
2021-02-10 10:06:09 +00:00
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.shortcuts import get_object_or_404, redirect, render
|
|
|
|
from django.urls import reverse
|
2018-06-21 18:03:46 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
|
|
from cotisations.models import Facture as Invoice
|
2018-07-13 20:28:10 +00:00
|
|
|
from cotisations.utils import find_payment_method
|
2018-06-21 18:03:46 +00:00
|
|
|
|
2018-07-02 12:41:02 +00:00
|
|
|
from .forms import InvoiceForm
|
2021-02-10 10:06:09 +00:00
|
|
|
from .models import ChequePayment
|
2018-06-21 18:03:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def cheque(request, invoice_pk):
|
2018-07-07 22:01:06 +00:00
|
|
|
"""This view validate an invoice with the data from a cheque."""
|
2018-06-21 18:03:46 +00:00
|
|
|
invoice = get_object_or_404(Invoice, pk=invoice_pk)
|
2018-07-13 20:28:10 +00:00
|
|
|
payment_method = find_payment_method(invoice.paiement)
|
2018-06-21 18:03:46 +00:00
|
|
|
if invoice.valid or not isinstance(payment_method, ChequePayment):
|
2019-11-04 16:55:03 +00:00
|
|
|
messages.error(request, _("You can't pay this invoice with a cheque."))
|
|
|
|
return redirect(reverse("users:profil", kwargs={"userid": request.user.pk}))
|
2018-07-02 12:41:02 +00:00
|
|
|
form = InvoiceForm(request.POST or None, instance=invoice)
|
2018-06-21 18:03:46 +00:00
|
|
|
if form.is_valid():
|
2018-07-02 12:41:02 +00:00
|
|
|
form.instance.valid = True
|
2020-02-15 12:30:37 +00:00
|
|
|
# For is saved in call to end_payment
|
2018-07-02 12:41:02 +00:00
|
|
|
return form.instance.paiement.end_payment(
|
2019-11-04 16:55:03 +00:00
|
|
|
form.instance, request, use_payment_method=False
|
2018-07-02 12:41:02 +00:00
|
|
|
)
|
2018-06-21 18:03:46 +00:00
|
|
|
return render(
|
|
|
|
request,
|
2019-11-04 16:55:03 +00:00
|
|
|
"cotisations/payment.html",
|
|
|
|
{"form": form, "amount": invoice.prix_total()},
|
2018-06-21 18:03:46 +00:00
|
|
|
)
|