Skip to content

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

Fix packaging slip generation to handle order groups without shipping address, add regression test and include changes in invoices for consistency

Rafał Pitoń0dfb0c85ab37
diff --git a/templates/dashboard/order/pdf/invoice.html b/templates/dashboard/order/pdf/invoice.html
index 699860897c..4da673d68a 100644
--- a/templates/dashboard/order/pdf/invoice.html
+++ b/templates/dashboard/order/pdf/invoice.html
@@ -23,9 +23,13 @@
<thead>
<tr>
{% if order.shipping_address %}
- <th align="left" width="50%">{% trans "Shipping Details" context "Invoice table header" %}</th>
+ <th align="left" width="50%">
+ {% trans "Shipping Details" context "Invoice table header" %}
+ </th>
{% endif %}
- <th align="left" width="50%">{% trans "Billing Details" context "Invoice table header" %}</th>
+ <th align="left" {% if order.shipping_address %} width="50%"{% endif %}>
+ {% trans "Billing Details" context "Invoice table header" %}
+ </th>
</tr>
</thead>
<tbody>
diff --git a/templates/dashboard/order/pdf/packing_slip.html b/templates/dashboard/order/pdf/packing_slip.html
index fc7f046345..865eb2074e 100644
--- a/templates/dashboard/order/pdf/packing_slip.html
+++ b/templates/dashboard/order/pdf/packing_slip.html
@@ -22,21 +22,29 @@
<h2>{% trans "Packing Slips" context "Packing slips header" %}</h2>
<table width="100%" border="1" cellspacing="0">
<thead>
- <tr>
- <th align="left" width="50%">{% trans "Shipping Details" context "Packing slip shipping details" %}</th>
- <th align="left" width="50%">{% trans "Billing Details" context "Packing slip shipping details" %}</th>
- </tr>
- </thead>
+ <tr>
+ {% if group.order.shipping_address %}
+ <th align="left" width="50%">
+ {% trans "Shipping Details" context "Packing slip shipping details" %}
+ </th>
+ {% endif %}
+ <th align="left"{% if group.order.shipping_address %} width="50%"{% endif %}>
+ {% trans "Billing Details" context "Packing slip shipping details" %}
+ </th>
+ </tr>
+ </thead>
<tbody>
<tr>
- <td valign="top">
- {% with group.order.shipping_address as address %}
- <h2>
- {% trans "Shipping address" context "Packing slip shipping address" %}
- </h2>
- {% include 'dashboard/includes/_address.html' with address=address only %}
- {% endwith %}
- </td>
+ {% if group.order.shipping_address %}
+ <td valign="top">
+ {% with group.order.shipping_address as address %}
+ <h2>
+ {% trans "Shipping address" context "Packing slip shipping address" %}
+ </h2>
+ {% include 'dashboard/includes/_address.html' with address=address only %}
+ {% endwith %}
+ </td>
+ {% endif %}
<td valign="top">
{% with group.order.billing_address as address %}
<h2>
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
index 85cbea6334..838ac07b12 100644
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -314,6 +314,25 @@ def test_view_order_invoice(
assert response['Content-Disposition'] == 'filename=%s' % name
+def test_view_order_invoice_without_shipping(
+ admin_client, order_with_lines_and_stock, billing_address):
+ """
+ Regression test for #1536:
+ user downloads the invoice for order without shipping address
+ """
+ order_with_lines_and_stock.billing_address = billing_address
+ order_with_lines_and_stock.save()
+ url = reverse(
+ 'dashboard:order-invoice', kwargs={
+ 'order_pk': order_with_lines_and_stock.id
+ })
+ response = admin_client.get(url)
+ assert response.status_code == 200
+ assert response['content-type'] == 'application/pdf'
+
+
@pytest.mark.integration
@pytest.mark.django_db
def test_view_order_packing_slips(
@@ -339,6 +358,24 @@ def test_view_order_packing_slips(
assert response['Content-Disposition'] == 'filename=%s' % name
+def test_view_order_packing_slips_without_shipping(
+ admin_client, order_with_lines_and_stock, billing_address):
+ """Regression test for #1536:
+ user downloads the packaging slips for order without shipping address
+ """
+ order_with_lines_and_stock.billing_address = billing_address
+ order_with_lines_and_stock.save()
+ url = reverse(
+ 'dashboard:order-packing-slips', kwargs={
+ 'group_pk': order_with_lines_and_stock.groups.all()[0].pk
+ })
+ response = admin_client.get(url)
+ assert response.status_code == 200
+ assert response['content-type'] == 'application/pdf'
+
+
@pytest.mark.integration
@pytest.mark.django_db
def test_view_change_order_line_stock_valid(