Changeset - 83b11cd7224d
[Not reviewed]
0 3 0
Christopher Neugebauer - 8 years ago 2016-03-24 03:20:29
chrisjrn@gmail.com
Fixes invoicing payment logic
3 files changed with 16 insertions and 2 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/invoice.py
Show inline comments
...
 
@@ -113,24 +113,24 @@ class InvoiceController(object):
 
        if self.invoice.cart is not None:
 
            cart = CartController(self.invoice.cart)
 
            cart.validate_cart()  # Raises ValidationError if invalid
 

	
 
        ''' Adds a payment '''
 
        payment = rego.Payment.objects.create(
 
            invoice=self.invoice,
 
            reference=reference,
 
            amount=amount,
 
        )
 
        payment.save()
 

	
 
        payments = rego.Payment.objects .filter(invoice=self.invoice)
 
        payments = rego.Payment.objects.filter(invoice=self.invoice)
 
        agg = payments.aggregate(Sum("amount"))
 
        total = agg["amount__sum"]
 

	
 
        if total == self.invoice.value:
 
            self.invoice.paid = True
 

	
 
            cart = self.invoice.cart
 
            cart.active = False
 
            cart.save()
 

	
 
            self.invoice.save()
registrasion/templates/invoice.html
Show inline comments
...
 
@@ -24,14 +24,28 @@
 
      <td>{{line_item.price}}</td>
 
      <td><!-- multiply --> FIXME</td>
 
    </tr>
 
  {% endfor %}
 
  <tr>
 
    <th>TOTAL</th>
 
    <td></td>
 
    <td></td>
 
    <td>{{ invoice.value }}</td>
 
  </tr>
 
</table>
 

	
 
<table>
 
  <tr>
 
    <th>Payment time</th>
 
    <th>Reference</th>
 
    <th>Amount</th>
 
  </tr>
 
  {% for payment in invoice.payment_set.all %}
 
    <tr>
 
      <td>{{payment.time}}</td>
 
      <td>{{payment.reference}}</td>
 
      <td>{{payment.amount}}</td>
 
    </tr>
 
  {% endfor %}
 
</table>
 

	
 
{% endblock %}
registrasion/views.py
Show inline comments
...
 
@@ -208,16 +208,16 @@ def invoice(request, invoice_id):
 
    return render(request, "invoice.html", data)
 

	
 
@login_required
 
def pay_invoice(request, invoice_id):
 
    ''' Marks the invoice with the given invoice id as paid.
 
    WORK IN PROGRESS FUNCTION. Must be replaced with real payment workflow.
 

	
 
    '''
 

	
 
    invoice_id = int(invoice_id)
 
    inv = rego.Invoice.objects.get(pk=invoice_id)
 
    current_invoice = InvoiceController(inv)
 
    if not inv.paid and not current_invoice.is_valid():
 
    if not inv.paid and current_invoice.is_valid():
 
        current_invoice.pay("Demo invoice payment", inv.value)
 

	
 
    return redirect("invoice", current_invoice.invoice.id)
0 comments (0 inline, 0 general)