from django.views.generic import FormView from django.shortcuts import get_object_or_404 from django.contrib import messages from localauth.mixins import SuperUserRequiredMixin from .forms import SepaApplyPaymentForm from .models import SepaPaymentReference, SepaInvoicePayment class SepaApplyPaymentView(SuperUserRequiredMixin, FormView): form_class = SepaApplyPaymentForm success_url = '/' def form_valid(self, form): reference = form.cleaned_data["reference"] pr = get_object_or_404(SepaPaymentReference, reference=reference) invoice = pr.invoice SepaInvoicePayment.objects.create(invoice=invoice, amount=form.cleaned_data["amount"]) messages.success(self.request, "Zahlung angewendet.") return super().form_valid(form)