def manual_payment(request, invoice_id): ''' Allows staff to make manual payments or refunds on an invoice.''' FORM_PREFIX = "manual_payment" if not request.user.is_staff: raise Http404() invoice_id = int(invoice_id) inv = get_object_or_404(commerce.Invoice, pk=invoice_id) current_invoice = InvoiceController(inv) form = forms.ManualPaymentForm( request.POST or None, prefix=FORM_PREFIX, ) if request.POST and form.is_valid(): form.instance.invoice = inv form.save() current_invoice.update_status() form = forms.ManualPaymentForm(prefix=FORM_PREFIX) data = { "invoice": inv, "form": form, } return render(request, "registrasion/manual_payment.html", data)
def demopay(request, invoice_id, access_code): ''' Marks the invoice with the given invoice id as paid. ''' invoice_id = int(invoice_id) inv = get_object_or_404(rego.Invoice.objects, pk=invoice_id) invoice = InvoiceController(inv) if not invoice.can_view(user=request.user, access_code=access_code): raise Http404() to_invoice = redirect("invoice", invoice.invoice.id, access_code) try: invoice.validate_allowed_to_pay( ) # Verify that we're allowed to do this. except ValidationError as ve: messages.error(request, ve.message) return to_invoice # Create the payment object models.DemoPayment.objects.create( invoice=invoice.invoice, reference="Demo payment by user: "******"This invoice was successfully paid.") return to_invoice
def demopay(request, invoice_id, access_code): ''' Marks the invoice with the given invoice id as paid. ''' invoice_id = int(invoice_id) inv = get_object_or_404(rego.Invoice.objects,pk=invoice_id) invoice = InvoiceController(inv) if not invoice.can_view(user=request.user, access_code=access_code): raise Http404() to_invoice = redirect("invoice", invoice.invoice.id, access_code) try: invoice.validate_allowed_to_pay() # Verify that we're allowed to do this. except ValidationError as ve: messages.error(request, ve.message) return to_invoice # Create the payment object models.DemoPayment.objects.create( invoice=invoice.invoice, reference="Demo payment by user: "******"This invoice was successfully paid.") return to_invoice
def manual_payment(request, invoice_id): ''' Allows staff to make manual payments or refunds on an invoice.''' FORM_PREFIX = "manual_payment" if not request.user.is_staff: raise Http404() invoice_id = int(invoice_id) inv = get_object_or_404(commerce.Invoice, pk=invoice_id) current_invoice = InvoiceController(inv) form = forms.ManualPaymentForm( request.POST or None, prefix=FORM_PREFIX, ) if request.POST and form.is_valid(): form.instance.invoice = inv form.save() current_invoice.update_status() form = forms.ManualPaymentForm(prefix=FORM_PREFIX) data = { "invoice": inv, "form": form, } return render(request, "registrasion/manual_payment.html", data)
def apply_to_invoice(self, invoice): ''' Applies the total value of this credit note to the specified invoice. If this credit note overpays the invoice, a new credit note containing the residual value will be created. Raises ValidationError if the given invoice is not allowed to be paid. ''' # Circular Import from registrasion.controllers.invoice import InvoiceController inv = InvoiceController(invoice) inv.validate_allowed_to_pay() # Apply payment to invoice commerce.CreditNoteApplication.objects.create( parent=self.credit_note, invoice=invoice, amount=self.credit_note.value, reference="Applied credit note #%d" % self.credit_note.id, ) inv.update_status()