Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Make invoice per order instead of per group
dominik-zeglen468beb518677
diff --git a/saleor/dashboard/order/urls.py b/saleor/dashboard/order/urls.pyindex cb4fe456e0..772192df53 100644--- a/saleor/dashboard/order/urls.py+++ b/saleor/dashboard/order/urls.py@@ -34,7 +34,7 @@ urlpatterns = [url(r'^(?P<order_pk>\d+)/shipment/(?P<group_pk>\d+)/cancel/$',views.cancel_delivery_group, name='cancel-delivery-group'),- url(r'^(?P<group_pk>\d+)/invoice/$',+ url(r'^(?P<order_pk>\d+)/invoice/$',views.order_invoice, name='order-invoice'),url(r'^(?P<group_pk>\d+)/packing-slips/$',views.order_packing_slip, name='order-packing-slips')]diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.pyindex 008619f4cd..0837e11571 100644--- a/saleor/dashboard/order/utils.py+++ b/saleor/dashboard/order/utils.py@@ -2,7 +2,7 @@ from django.contrib.sites.shortcuts import get_current_sitefrom django.template.loader import get_templatefrom ...settings import STATIC_URL-from ...order.models import DeliveryGroup+from ...order.models import DeliveryGroup, OrderINVOICE_TEMPLATE = 'dashboard/order/pdf/invoice.html'@@ -26,18 +26,18 @@ def _create_pdf(rendered_template, absolute_url):return pdf_file-def create_invoice_pdf(group_pk, absolute_url):- group = (DeliveryGroup.objects.prefetch_related(- 'items', 'order', 'order__user', 'order__shipping_address',- 'order__billing_address', 'order__voucher', 'order__groups').get(- pk=group_pk))- first_delivery_group = False- if str(group.order.groups.order_by('pk')[0].pk) == group_pk:- first_delivery_group = True- ctx = {'group': group, 'first_delivery_group': first_delivery_group}+def create_invoice_pdf(order_pk, absolute_url):+ order = (Order.objects.prefetch_related(+ 'user', 'shipping_address',+ 'billing_address', 'voucher').get(+ pk=order_pk))+ shipping_methods = [+ {'name': d.shipping_method_name,+ 'price': d.shipping_price} for d in order.groups.all()]+ ctx = {'order': order, 'shipping_methods': shipping_methods}rendered_template = get_template(INVOICE_TEMPLATE).render(ctx)pdf_file = _create_pdf(rendered_template, absolute_url)- return pdf_file, group+ return pdf_file, orderdef create_packing_slip_pdf(group_pk, absolute_url):diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex ac7543a4e8..a3c6535618 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -374,11 +374,11 @@ def remove_order_voucher(request, order_pk):@staff_member_required@permission_required('order.edit_order')-def order_invoice(request, group_pk):+def order_invoice(request, order_pk):absolute_url = get_statics_absolute_url(request)- pdf_file, group = create_invoice_pdf(group_pk, absolute_url)+ pdf_file, order = create_invoice_pdf(order_pk, absolute_url)response = HttpResponse(pdf_file, content_type='application/pdf')- name = "invoice-%s-%s" % (group.order.id, group.id)+ name = "invoice-%s" % order.idresponse['Content-Disposition'] = 'filename=%s' % namereturn responsediff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.htmlindex 93c68f108e..f868ca00da 100644--- a/templates/dashboard/order/detail.html+++ b/templates/dashboard/order/detail.html@@ -203,6 +203,9 @@{% trans "Release" context "Order summary card action" %}</a>{% endif %}+ <a href="{% url 'dashboard:order-invoice' order_pk=order.pk %}" data-href="" class="btn btn-flat" target="_blank">+ {% trans "Invoice" context "Order detail action" %}+ </a></div>{% endif %}{% endif %}@@ -355,9 +358,6 @@{% trans "Cancel this shipment" context "Shipment group table action" %}</a>{% endif %}- <a href="{% url 'dashboard:order-invoice' group_pk=group.pk %}" data-href="" class="btn btn-flat" target="_blank">- {% trans "Invoice" context "Order detail action" %}- </a><a href="{% url 'dashboard:order-packing-slips' group_pk=group.pk %}" data-href="" class="btn btn-flat" target="_blank">{% trans "Packing Slips" context "Order detail action" %}</a>diff --git a/templates/dashboard/order/pdf/invoice.html b/templates/dashboard/order/pdf/invoice.htmlindex 91d34a384f..3657b0a434 100644--- a/templates/dashboard/order/pdf/invoice.html+++ b/templates/dashboard/order/pdf/invoice.html@@ -5,7 +5,7 @@<html><head>- <title>Invoice, order ID: {{ group.order.id }}</title>+ <title>Invoice, order ID: {{ order.id }}</title><link rel="stylesheet" type="text/css" href="{% static '/assets/document.css' %}" /></head><body>@@ -14,7 +14,7 @@<img src="{% static '/images/saleor_logo_black.svg' %}"></div><div- style="float:right">{{ group.order.created }}<br>{% trans 'Order ID:' context 'Invoice header' %} {{ group.order.id }}+ style="float:right">{{ order.created }}<br>{% trans 'Order ID:' context 'Invoice header' %} {{ order.id }}</div></header>@@ -29,7 +29,7 @@<tbody><tr><td valign="top">- {% with group.order.shipping_address as address %}+ {% with order.shipping_address as address %}<h2>{% trans "Shipping address" context "Invoice shipping address" %}</h2>@@ -37,7 +37,7 @@{% endwith %}</td><td valign="top">- {% with group.order.billing_address as address %}+ {% with order.billing_address as address %}<h2>{% trans "Billing address" context "Invoice billing address" %}</h2>@@ -49,29 +49,29 @@</table><h2>{% trans "Items Ordered" context "Order invoice" %}</h2>-{% if group %}- <table class="data-table order-table bordered">+{% if order %}+ <table class="highlight data-table order-table bordered"><thead><tr><th class="wide">- {% trans "Item" context "Shipment group table header" %}+ {% trans "Item" context "Shipment order table header" %}</th><th>- {% trans "SKU" context "Shipment group table header" %}+ {% trans "SKU" context "Shipment order table header" %}</th><th class="right-align">- {% trans "Price" context "Shipment group table header" %}+ {% trans "Price" context "Shipment order table header" %}</th><th class="right-align">- {% trans "Quantity" context "Shipment group table header" %}+ {% trans "Quantity" context "Shipment order table header" %}</th><th class="right-align">- {% trans "Total" context "Shipment group table header" %}+ {% trans "Total" context "Shipment order table header" %}</th></tr></thead><tbody>- {% for item in group.items.all %}+ {% for item in order.get_items.all %}<tr><td>{{ item.product_name|truncatechars:40 }}<br>@@ -90,30 +90,32 @@</td></tr>{% endfor %}- {% if group.shipping_price.gross or group.is_shipping_required %}- <tr>- <td colspan="4">- {% blocktrans trimmed with group_shipping_method_name=group.shipping_method_name context "Shipment group table item column data" %}- Shipping ({{ group_shipping_method_name }})- {% endblocktrans %}- </td>- <td class="right-align">- {% gross group.shipping_price html=True %}- </td>- </tr>+ {% if order.shipping_price.gross or order.is_shipping_required %}+ {% for shipping in shipping_methods %}+ <tr>+ <td colspan="4">+ {% blocktrans trimmed with shipping_name=shipping.name context "Shipment order table item column data" %}+ Shipping ({{ shipping_name }})+ {% endblocktrans %}+ </td>+ <td class="right-align">+ {% gross shipping.price html=True %}+ </td>+ </tr>+ {% endfor %}{% endif %}</tbody></table>{% endif %}-<table class="bordered responsive data-table">+<table class="bordered highlight responsive data-table"><tbody><tr><td class="wide">{% trans "Subtotal" context "Order subtotal" %}</td><td class="right-align">- {% gross group.get_subtotal_without_voucher html=True %}+ {% gross order.get_subtotal_without_voucher html=True %}</td></tr><tr>@@ -121,21 +123,19 @@{% trans "Total Shipping Price" context "Order totals header" %}</td><td class="right-align">- {% gross group.shipping_price html=True %}+ {% gross order.get_total_shipping html=True %}</td></tr>- {% if first_delivery_group %}- {% if group.order.voucher %}+ {% if order.voucher %}<tr><td>- {% trans "Voucher" context "Order voucher header" %} {{ group.order.voucher }}+ {% trans "Voucher" context "Order voucher header" %} {{ order.voucher }}</td><td class="right-align">- {% gross group.order.discount|discount_amount_for:group.order.total html=True %}+ {% gross order.discount|discount_amount_for:order.total html=True %}</td></tr>{% endif %}- {% endif %}</tbody><tfoot><tr>@@ -143,11 +143,10 @@{% trans "Grand total" context "Order totals header" %}</td><td>- {% gross group.get_total html=True %}+ {% gross order.get_total html=True %}</td></tr></tfoot></table></body></html>-