Example #1
0
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
Example #2
0
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
Example #3
0
    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()