diff --git a/registrasion/controllers/invoice.py b/registrasion/controllers/invoice.py
index 5ce562f3..e9a654e4 100644
--- a/registrasion/controllers/invoice.py
+++ b/registrasion/controllers/invoice.py
@@ -59,20 +59,23 @@ class InvoiceController(object):
# TODO: calculate line items.
product_items = rego.ProductItem.objects.filter(cart=cart)
+ product_items = product_items.order_by(
+ "product__category__order", "product__order"
+ )
discount_items = rego.DiscountItem.objects.filter(cart=cart)
invoice_value = Decimal()
for item in product_items:
+ product = item.product
line_item = rego.LineItem.objects.create(
invoice=invoice,
- description=item.product.name,
+ description="%s - %s" % (product.category.name, product.name),
quantity=item.quantity,
- price=item.product.price,
+ price=product.price,
)
line_item.save()
invoice_value += line_item.quantity * line_item.price
for item in discount_items:
-
line_item = rego.LineItem.objects.create(
invoice=invoice,
description=item.discount.description,
diff --git a/registrasion/templates/invoice.html b/registrasion/templates/invoice.html
new file mode 100644
index 00000000..a66132cf
--- /dev/null
+++ b/registrasion/templates/invoice.html
@@ -0,0 +1,37 @@
+
+
+{% extends "site_base.html" %}
+{% block body %}
+
+
Invoice {{ invoice.id }}
+
+
+ - Void: {{ invoice.void }}
+ - Paid: {{ invoice.paid }}
+
+
+
+
+ Description |
+ Quantity |
+ Price/Unit |
+ Total |
+
+ {% for line_item in invoice.lineitem_set.all %}
+
+ {{line_item.description}} |
+ {{line_item.quantity}} |
+ {{line_item.price}} |
+ FIXME |
+
+ {% endfor %}
+
+ TOTAL |
+ |
+ |
+ {{ invoice.value }} |
+
+
+
+
+{% endblock %}
diff --git a/registrasion/urls.py b/registrasion/urls.py
index 257f2e2f..d8a1c6db 100644
--- a/registrasion/urls.py
+++ b/registrasion/urls.py
@@ -3,5 +3,6 @@ from django.conf.urls import url, patterns
urlpatterns = patterns(
"registrasion.views",
url(r"^category/([0-9]+)$", "product_category", name="product_category"),
- # url(r"^category$", "product_category", name="product_category"),
+ url(r"^checkout$", "checkout", name="checkout"),
+ url(r"^invoice/([0-9]+)$", "invoice", name="invoice"),
)
diff --git a/registrasion/views.py b/registrasion/views.py
index 1b5bc254..4e5f372a 100644
--- a/registrasion/views.py
+++ b/registrasion/views.py
@@ -1,11 +1,13 @@
from registrasion import forms
from registrasion import models as rego
from registrasion.controllers.cart import CartController
+from registrasion.controllers.invoice import InvoiceController
from django.contrib.auth.decorators import login_required
from django.core.exceptions import ObjectDoesNotExist
from django.db import transaction
from django.forms import formset_factory
+from django.shortcuts import redirect
from django.shortcuts import render
from functools import partial, wraps
@@ -55,3 +57,28 @@ def product_category(request, category_id):
}
return render(request, "product_category.html", data)
+
+@login_required
+def checkout(request):
+ ''' Runs checkout for the current cart of items, ideally generating an
+ invoice. '''
+
+ current_cart = CartController.for_user(request.user)
+ current_invoice = InvoiceController.for_cart(current_cart.cart)
+
+ return redirect("invoice", current_invoice.invoice.id)
+
+
+@login_required
+def invoice(request, invoice_id):
+ ''' Displays an invoice for a given invoice id. '''
+
+ invoice_id = int(invoice_id)
+ inv = rego.Invoice.objects.get(pk=invoice_id)
+ current_invoice = InvoiceController(inv)
+
+ data = {
+ "invoice": current_invoice.invoice,
+ }
+
+ return render(request, "invoice.html", data)