Skip to content

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

Packing slips per fulfillment

Anna Siwik062552d3a965
diff --git a/saleor/dashboard/order/urls.py b/saleor/dashboard/order/urls.py
index 1407a89bda..a2c874c1f6 100644
--- a/saleor/dashboard/order/urls.py
+++ b/saleor/dashboard/order/urls.py
@@ -36,7 +36,7 @@ urlpatterns = [
views.cancel_fulfillment, name='fulfillment-cancel'),
url(r'^(?P<order_pk>\d+)/fulfillment/(?P<fulfillment_pk>\d+)/tracking/$',
views.change_fulfillment_tracking, name='fulfillment-change-tracking'),
+ url(r'^(?P<order_pk>\d+)/fulfillment/(?P<fulfillment_pk>\d+)/packing-slips/$', # noqa
+ views.fulfillment_packing_slips, name='fulfillment-packing-slips'),
url(r'^(?P<order_pk>\d+)/invoice/$',
- views.order_invoice, name='order-invoice'),
- url(r'^(?P<order_pk>\d+)/packing-slips/$',
- views.order_packing_slip, name='order-packing-slips')]
+ views.order_invoice, name='order-invoice')]
diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.py
index bb1ea087e0..dc4b79a7fe 100644
--- a/saleor/dashboard/order/utils.py
+++ b/saleor/dashboard/order/utils.py
@@ -32,8 +32,8 @@ def create_invoice_pdf(order, absolute_url):
return pdf_file, order
-def create_packing_slip_pdf(order, absolute_url):
- ctx = {'order': order}
+def create_packing_slip_pdf(order, fulfillment, absolute_url):
+ ctx = {'order': order, 'fulfillment': fulfillment}
rendered_template = get_template(PACKING_SLIP_TEMPLATE).render(ctx)
pdf_file = _create_pdf(rendered_template, absolute_url)
return pdf_file, order
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 6123e2fb0b..4d85095658 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -347,12 +347,15 @@ def order_invoice(request, order_pk):
@staff_member_required
@permission_required('order.edit_order')
-def order_packing_slip(request, order_pk):
+def fulfillment_packing_slips(request, order_pk, fulfillment_pk):
orders = Order.objects.prefetch_related(
- 'lines', 'user', 'shipping_address', 'billing_address')
+ 'user', 'shipping_address', 'billing_address')
order = get_object_or_404(orders, pk=order_pk)
+ fulfillments = order.fulfillments.prefetch_related(
+ 'lines', 'lines__order_line')
+ fulfillment = get_object_or_404(fulfillments, pk=fulfillment_pk)
absolute_url = get_statics_absolute_url(request)
- pdf_file, order = create_packing_slip_pdf(order, absolute_url)
+ pdf_file, order = create_packing_slip_pdf(order, fulfillment, absolute_url)
response = HttpResponse(pdf_file, content_type='application/pdf')
name = "packing-slip-%s" % (order.id,)
response['Content-Disposition'] = 'filename=%s' % name
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index 32832e9994..ca4f265f57 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -334,9 +334,6 @@
<a href="{% url 'dashboard:fulfill-order-lines' order_pk=order.pk %}" class="btn-flat waves-effect" title="{% trans "Fulfill order" context "Order summary card action title" %}">
{% trans "Fulfill" context "Order summary card action" %}
</a>
- <a href="{% url 'dashboard:order-packing-slips' order_pk=order.pk %}" data-href="" class="btn-flat waves-effect" target="_blank">
- {% trans "Packing Slips" context "Order detail action" %}
- </a>
{% endif %}
{% if order.can_edit %}
<a href="#base-modal" data-href="{% url 'dashboard:add-variant-to-order' order_pk=order.pk %}" class="btn-flat waves-effect modal-trigger-custom" title="{% trans "Add product to order" context "Order summary card action title" %}">
@@ -448,19 +445,25 @@
</tbody>
</table>
</div>
- {% if perms.order.edit_order and fulfillment.can_edit %}
+ {% if perms.order.edit_order %}
<div class="data-table-action">
- <a href="#base-modal" data-href="{% url 'dashboard:fulfillment-cancel' order_pk=order.pk fulfillment_pk=fulfillment.pk %}"
- class="btn-flat waves-effect modal-trigger-custom" title="{% trans "Cancel fulfillment" context "Fulfillment summary card action title" %}">
- {% trans "Cancel" context "Fulfillment summary card action" %}
- </a>
- <a href="#base-modal" data-href="{% url 'dashboard:fulfillment-change-tracking' order_pk=order.pk fulfillment_pk=fulfillment.pk %}"
- class="btn-flat waves-effect modal-trigger-custom" title="{% trans "Edit tracking number" context "Fulfillment summary card action title" %}">
- {% if fulfillment.tracking_number %}
- {% trans "Edit tracking" context "Fulfillment summary card action" %}
- {% else %}
- {% trans "Add tracking" context "Fulfillment summary card action" %}
- {% endif %}
+ {% if fulfillment.can_edit %}
+ <a href="#base-modal" data-href="{% url 'dashboard:fulfillment-cancel' order_pk=order.pk fulfillment_pk=fulfillment.pk %}"
+ class="btn-flat waves-effect modal-trigger-custom" title="{% trans "Cancel fulfillment" context "Fulfillment summary card action title" %}">
+ {% trans "Cancel" context "Fulfillment summary card action" %}
+ </a>
+ <a href="#base-modal" data-href="{% url 'dashboard:fulfillment-change-tracking' order_pk=order.pk fulfillment_pk=fulfillment.pk %}"
+ class="btn-flat waves-effect modal-trigger-custom" title="{% trans "Edit tracking number" context "Fulfillment summary card action title" %}">
+ {% if fulfillment.tracking_number %}
+ {% trans "Edit tracking" context "Fulfillment summary card action" %}
+ {% else %}
+ {% trans "Add tracking" context "Fulfillment summary card action" %}
+ {% endif %}
+ </a>
+ {% endif %}
+ <a href="{% url 'dashboard:fulfillment-packing-slips' order_pk=order.pk fulfillment_pk=fulfillment.pk %}"
+ data-href="" class="btn-flat waves-effect" target="_blank">
+ {% trans "Packing Slips" context "Order detail action" %}
</a>
</div>
{% endif %}
diff --git a/templates/dashboard/order/pdf/packing_slip.html b/templates/dashboard/order/pdf/packing_slip.html
index 9a2f26a3a4..11aedcacab 100644
--- a/templates/dashboard/order/pdf/packing_slip.html
+++ b/templates/dashboard/order/pdf/packing_slip.html
@@ -73,18 +73,16 @@
</tr>
</thead>
<tbody>
- {% for line in order.get_unfulfilled_lines %}
+ {% for line in fulfillment %}
<tr>
<td>
- {{ line.product_name }}<br>
+ {{ line.order_line.product_name }}<br>
</td>
<td>
- {{ line.product_sku }}
+ {{ line.order_line.product_sku }}
</td>
<td class="right-align">
- {% blocktrans trimmed with quantity_unfulfilled=line.quantity_unfulfilled quantity=line.quantity %}
- {{ quantity_unfulfilled }} (of {{ quantity }})
- {% endblocktrans %}
+ {{ line.quantity }}
</td>
</tr>
{% endfor %}
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
index 61c1f1951c..40c54a0f86 100644
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -249,31 +249,33 @@ def test_view_order_invoice_without_shipping(
@pytest.mark.integration
@pytest.mark.django_db
-def test_view_order_packing_slips(
- admin_client, order_with_lines_and_stock, billing_address):
- order_with_lines_and_stock.shipping_address = billing_address
- order_with_lines_and_stock.billing_address = billing_address
- order_with_lines_and_stock.save()
+def test_view_fulfillment_packing_slips(
+ admin_client, fulfilled_order, billing_address):
+ fulfilled_order.shipping_address = billing_address
+ fulfilled_order.billing_address = billing_address
+ fulfilled_order.save()
+ fulfillment = fulfilled_order.fulfillments.first()
url = reverse(
- 'dashboard:order-packing-slips', kwargs={
- 'order_pk': order_with_lines_and_stock.pk})
+ 'dashboard:fulfillment-packing-slips', kwargs={
+ 'order_pk': fulfilled_order.pk, 'fulfillment_pk': fulfillment.pk})
response = admin_client.get(url)
assert response.status_code == 200
assert response['content-type'] == 'application/pdf'
- name = "packing-slip-%s" % (order_with_lines_and_stock.id,)
+ name = "packing-slip-%s" % (fulfilled_order.id,)
assert response['Content-Disposition'] == 'filename=%s' % name
@pytest.mark.integration
@pytest.mark.django_db
-def test_view_order_packing_slips_without_shipping(
- admin_client, order_with_lines_and_stock, billing_address):
+def test_view_fulfillment_packing_slips_without_shipping(
+ admin_client, fulfilled_order, billing_address):
# Regression test for #1536
- order_with_lines_and_stock.billing_address = billing_address
- order_with_lines_and_stock.save()
+ fulfilled_order.billing_address = billing_address
+ fulfilled_order.save()
+ fulfillment = fulfilled_order.fulfillments.first()
url = reverse(
- 'dashboard:order-packing-slips', kwargs={
- 'order_pk': order_with_lines_and_stock.pk})
+ 'dashboard:fulfillment-packing-slips', kwargs={
+ 'order_pk': fulfilled_order.pk, 'fulfillment_pk': fulfillment.pk})
response = admin_client.get(url)
assert response.status_code == 200
assert response['content-type'] == 'application/pdf'