Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Adds Packing Slips to the Dashboard's Order page

Anderson Santos349f79cd1faf
diff --git a/saleor/dashboard/order/urls.py b/saleor/dashboard/order/urls.py
index c36d2f4b74..ff409ea9a6 100644
--- a/saleor/dashboard/order/urls.py
+++ b/saleor/dashboard/order/urls.py
@@ -15,6 +15,8 @@ urlpatterns = [
views.address_view, name='address-edit'),
url(r'^(?P<order_pk>\d+)/invoice/$',
views.order_invoice, name='order-invoice'),
+ url(r'^(?P<order_pk>\d+)/packing-slips/$',
+ views.order_packing_slips, name='order-packing-slips'),
url(r'^(?P<order_pk>\d+)/payment/(?P<payment_pk>\d+)/capture/$',
views.capture_payment, name='capture-payment'),
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 9e5eb1af5d..ad3bb870a8 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -410,3 +410,43 @@ def order_invoice(request, order_pk):
name = "invoice-{}".format(order.id)
response['Content-Disposition'] = 'filename={}'.format(name)
return response
+
+
+@staff_member_required
+def order_packing_slips(request, order_pk):
+ qs = (Order.objects
+ .select_related('user', 'shipping_address', 'billing_address')
+ .prefetch_related('notes', 'payments', 'history',
+ 'groups', 'groups__items'))
+ order = get_object_or_404(qs, pk=order_pk)
+ notes = order.notes.all()
+ all_payments = order.payments.exclude(status=PaymentStatus.INPUT)
+ payment = order.payments.last()
+ groups = list(order)
+ captured = preauthorized = Price(0, currency=order.get_total().currency)
+ balance = captured - order.get_total()
+ if payment:
+ can_capture = (
+ payment.status == PaymentStatus.PREAUTH and
+ order.status != OrderStatus.CANCELLED)
+ can_release = payment.status == PaymentStatus.PREAUTH
+ can_refund = payment.status == PaymentStatus.CONFIRMED
+ preauthorized = payment.get_total_price()
+ if payment.status == PaymentStatus.CONFIRMED:
+ captured = payment.get_captured_price()
+ balance = captured - order.get_total()
+ else:
+ can_capture = can_release = can_refund = False
+
+ ctx = {'order': order, 'all_payments': all_payments, 'payment': payment,
+ 'notes': notes, 'groups': groups, 'captured': captured,
+ 'preauthorized': preauthorized, 'can_capture': can_capture,
+ 'can_release': can_release, 'can_refund': can_refund,
+ 'balance': balance}
+ invoice_template = 'dashboard/order/packing_slips.html'
+ html_template = get_template(invoice_template).render(ctx)
+ pdf_file = HTML(string=html_template).write_pdf()
+ response = HttpResponse(pdf_file, content_type='application/pdf')
+ name = "invoice-{}".format(order.id)
+ response['Content-Disposition'] = 'filename={}'.format(name)
+ return response
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index dcc4e26043..1fb249fd30 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -40,10 +40,15 @@
</a>
</li>
<li>
- <a href="{% url "dashboard:order-invoice" order_pk=order.pk %}" data-href="" class="">
- {% trans "PDF Invoice" context "Order detail action" %}
- </a>
- </li>
+ <a href="{% url "dashboard:order-invoice" order_pk=order.pk %}" data-href="" class="">
+ {% trans "PDF Invoice" context "Order detail action" %}
+ </a>
+ </li>
+ <li>
+ <a href="{% url "dashboard:order-packing-slips" order_pk=order.pk %}" data-href="" class="">
+ {% trans "Packing Slips" context "Order detail action" %}
+ </a>
+ </li>
</ul>
{% endblock %}
diff --git a/templates/dashboard/order/packing_slips.html b/templates/dashboard/order/packing_slips.html
new file mode 100644
index 0000000000..befccb4997
--- /dev/null
+++ b/templates/dashboard/order/packing_slips.html
@@ -0,0 +1,96 @@
+{% load i18n static %}
+{% load prices_i18n %}
+{% load discount_amount_for from prices %}
+
+<h1>{% trans "Packing Slips" %}</h1>
+<table width="100%" border="0">
+ <tr>
+ <td>{% trans "Order ID:" %} {{ order.id }}</td>
+ <td align="right">{{ order.created }}</td>
+ </tr>
+</table>
+
+<h2>{% trans "Company Details" context "Order invoice" %}</h2>
+<table width="100%" border="1" cellspacing="0" cellpadding="10">
+<tr>
+ <th align="left" width="50%">{% trans "Shipping Details" %}</th>
+ <th align="left" width="50%">{% trans "Billing Details" %}</th>
+</tr>
+<tr>
+ <td valign="top">
+ <table border="0">
+ <div class="row">
+ <div class="col s12 m6 l12 p6">
+ {% with order.shipping_address as address %}
+ <div class="card">
+ <div class="card-content">
+ <span class="card-title black-text">
+ {% trans "Shipping address" context "" %}
+ </span>
+ {% include 'dashboard/includes/_address.html' with address=address only %}
+ </div>
+ </div>
+ </div>
+ {% endwith %}
+ </div>
+ </table>
+ </td>
+ <td valign="top">
+ <table border="0">
+ <div class="col s12 {% if address %}m6{% else %}m12{% endif %} l12 p6">
+ <div class="card">
+ <div class="card-content">
+ {% with order.billing_address as address %}
+ <span class="card-title black-text">
+ {% trans "Billing address" context "" %}
+ </span>
+ {% include 'dashboard/includes/_address.html' with address=address only %}
+ {% endwith %}
+ </div>
+ </div>
+ </div>
+ </table>
+ </td>
+</tr>
+</table>
+
+<h2>{% trans "Items Ordered" context "Order invoice" %}</h2>
+ {% for group in groups %}
+ <table class="bordered highlight responsive data-table">
+ <thead>
+ <tr>
+ <th>
+ </th>
+ <th class="wide">
+ {% trans "Item" context "Shipment group table header" %}
+ </th>
+ <th>
+ {% trans "SKU" context "Shipment group table header" %}
+ </th>
+ <th class="right-align">
+ {% trans "Quantity" context "Shipment group table header" %}
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for item in group.items.all %}
+ <tr>
+ <td>
+ <input type="checkbox">
+ </td>
+ <td>
+ {{ item.product_name }}<br>
+ </td>
+ <td>
+ {{ item.product_sku }}
+ </td>
+ <td class="right-align">
+ {{ item.quantity }}
+ </td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ {% endfor %}
+
+</table>
\ No newline at end of file
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
index 8ace583b2f..fd2a478b1a 100644
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -298,3 +298,27 @@ def test_view_order_invoice(admin_client, order_with_items_and_stock, billing_ad
response = admin_client.get(url)
assert response.status_code == 200
assert response['content-type'] == 'application/pdf'
+
+
+def test_view_order_packing_slips(admin_client, order_with_items_and_stock, billing_address):
+ """
+ user goes to order details page
+ user selects on extra menu Packing Slips
+ user downloads the packing slips as PDF file
+ """
+ # TODO: Invoice.html requires address otherwise it throws exception
+ # perhaps setting this in the order fixture?
+ order_with_items_and_stock.shipping_address = billing_address
+ order_with_items_and_stock.billing_address = billing_address
+ order_with_items_and_stock.save()
+
+ url = reverse(
+ 'dashboard:order-packing-slips', kwargs={
+ 'order_pk': order_with_items_and_stock.pk
+ })
+
+ response = admin_client.get(url)
+ assert response.status_code == 200
+ assert response['content-type'] == 'application/pdf'