Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add style to documents
dominik-zeglen965909057fbc
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex 133710e3be..db2e4bdb96 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -13,6 +13,7 @@ from django_prices.templatetags.prices_i18n import grossfrom payments import PaymentStatusfrom prices import Pricefrom weasyprint import HTML+from base64 import b64encodefrom ...core.utils import get_paginator_itemsfrom ...order import OrderStatus@@ -187,8 +188,8 @@ def orderline_change_quantity(request, order_pk, line_pk):'Dashboard message related to an order line','Changed quantity for product %(product)s from'' %(old_quantity)s to %(new_quantity)s') % {- 'product': item.product, 'old_quantity': old_quantity,- 'new_quantity': item.quantity}+ 'product': item.product, 'old_quantity': old_quantity,+ 'new_quantity': item.quantity}order.create_history_entry(comment=msg, user=request.user)messages.success(request, msg)return redirect('dashboard:order-details', order_pk=order.pk)@@ -223,8 +224,8 @@ def orderline_split(request, order_pk, line_pk):'Dashboard message related to delivery groups','Moved %(how_many)s items %(item)s from %(old_group)s'' to %(new_group)s') % {- 'how_many': how_many, 'item': item, 'old_group': old_group,- 'new_group': target_group}+ 'how_many': how_many, 'item': item, 'old_group': old_group,+ 'new_group': target_group}order.create_history_entry(comment=msg, user=request.user)messages.success(request, msg)return redirect('dashboard:order-details', order_pk=order.pk)@@ -380,13 +381,25 @@ def order_invoice(request, order_pk, group_pk):group = DeliveryGroup.objects.prefetch_related('items').get(pk=group_pk)ctx = {'order': order,'group': group}- rendered_template = get_template(- 'dashboard/order/pdf/invoice.html').render(ctx)- pdf_file = HTML(string=rendered_template).write_pdf()- response = HttpResponse(pdf_file, content_type='application/pdf')- name = "invoice-%s" % order.id- response['Content-Disposition'] = 'filename=%s' % name- return response+ with open('/app/saleor/static/assets/dashboard.css') as f:+ ctx['style'] = f.read()+ with open('/app/saleor/static/images/saleor_logo.svg') as f:+ ctx['logo'] = "data:image/svg+xml;charset=utf-8;base64," \+ + str(b64encode(bytes(f.read()+ .replace('white', '#333'),+ 'utf-8')),+ 'utf-8')+ # rendered_template = get_template(+ # 'dashboard/order/pdf/invoice.html').render(ctx)+ # pdf_file = HTML(string=rendered_template).write_pdf()+ # response = HttpResponse(pdf_file, content_type='application/pdf')+ # name = "invoice-%s" % order.id+ # response['Content-Disposition'] = 'filename=%s' % name+ # return response++ return TemplateResponse(request,+ 'dashboard/order/pdf/invoice.html',+ ctx)@staff_member_required@@ -397,6 +410,14 @@ def order_packing_slip(request, order_pk, group_pk):group = DeliveryGroup.objects.prefetch_related('items').get(pk=group_pk)ctx = {'order': order,'group': group}+ with open('/app/saleor/static/assets/dashboard.css') as f:+ ctx['style'] = f.read()+ with open('/app/saleor/static/images/saleor_logo.svg') as f:+ ctx['logo'] = "data:image/svg+xml;charset=utf-8;base64," \+ + str(b64encode(bytes(f.read()+ .replace('white', '#333'),+ 'utf-8')),+ 'utf-8')rendered_template = get_template('dashboard/order/pdf/packing_slip.html').render(ctx)pdf_file = HTML(string=rendered_template).write_pdf()diff --git a/templates/dashboard/order/pdf/invoice.html b/templates/dashboard/order/pdf/invoice.htmlindex 48a421c0fa..464266630e 100644--- a/templates/dashboard/order/pdf/invoice.html+++ b/templates/dashboard/order/pdf/invoice.html@@ -1,168 +1,207 @@{% load i18n static %}{% load prices_i18n %}{% load discount_amount_for from prices %}+{% load staticfiles %}+<style>+ {{ style }}+ html, body {+ font-size: 12px;+ }-<table width="100%" border="0">- <tr>- <td>{% trans "Order ID:" %} {{ order.id }}</td>- <td align="right">{{ order.created }}</td>- </tr>-</table>+ .order-table {+ margin-bottom: 30px;+ }++ .data-table {+ max-width: 100%;+ width: 100%;+ }++ .data-table tr {+ border-bottom: 1px #d0d0d0 solid;+ }++ .data-table tr:last-child {+ border-bottom: none;+ }++ .data-table td {+ height: 30px;+ padding: 10px;+ }++ header {+ margin-bottom: 5rem;+ }++ #invoice-footer {+ position: fixed;+ bottom: 0;+ width: 100%;+ text-align: center;+ }++ @page {+ @bottom-center {+ content: "Saleor eCommerce, Mirumee Software";+ }+ @bottom-right {+ content: "Page " counter(page) "/" counter(pages);+ }+ }+</style>++<header>+ <div style="float:left">+ <img src="{{ logo|safe }}">+ </div>+ <div+ style="float:right">{{ order.created }}<br>{% trans "Order ID:" %} {{ order.id }}+ </div>+</header><h2>{% trans "Company Details" context "Order invoice" %}</h2>-<table width="100%" border="1" cellspacing="0" cellpadding="10">-<tr>+<table width="100%" border="1" cellspacing="0">+ <thead>+ <tr><th align="left" width="50%">{% trans "Shipping Details" %}</th><th align="left" width="50%">{% trans "Billing Details" %}</th>-</tr>-<tr>+ </tr>+ </thead>+ <tbody>+ <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>+ {% with order.shipping_address as address %}+ <h2>+ {% trans "Shipping address" context "" %}+ </h2>+ {% include 'dashboard/includes/_address.html' with address=address only %}+ {% endwith %}</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>+ {% with order.billing_address as address %}+ <h2>+ {% trans "Billing address" context "" %}+ </h2>+ {% include 'dashboard/includes/_address.html' with address=address only %}+ {% endwith %}</td>-</tr>+ </tr>+ </tbody></table><h2>{% trans "Items Ordered" context "Order invoice" %}</h2>- {% if group %}- <table class="bordered highlight responsive data-table">+{% if group %}+ <table class="highlight data-table order-table bordered"><thead>- <tr>- <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 "Price" context "Shipment group table header" %}- </th>- <th class="right-align">- {% trans "Quantity" context "Shipment group table header" %}- </th>- <th class="right-align">- {% trans "Total" context "Shipment group table header" %}- </th>- </tr>+ <tr>+ <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 "Price" context "Shipment group table header" %}+ </th>+ <th class="right-align">+ {% trans "Quantity" context "Shipment group table header" %}+ </th>+ <th class="right-align">+ {% trans "Total" context "Shipment group table header" %}+ </th>+ </tr></thead>- <tfoot>- {% 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>- {% endif %}- </tfoot>- <tbody>- {% for item in group.items.all %}- <tr>- <td>- {{ item.product_name }}<br>- </td>- <td>- {{ item.product_sku }}- </td>- <td class="right-align">- {% gross item.get_price_per_item html=True %}- </td>- <td class="right-align">- {{ item.quantity }}+ <tbody>+ {% for item in group.items.all %}+ <tr>+ <td>+ {{ item.product_name|truncatechars:40 }}<br>+ </td>+ <td>+ {{ item.product_sku }}+ </td>+ <td class="right-align">+ {% gross item.get_price_per_item html=True %}+ </td>+ <td class="right-align">+ {{ item.quantity }}</td><td class="right-align">{% gross item.get_total html=True %}</td></tr>- {% endfor %}+ {% 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>+ {% endif %}</tbody></table>- {% endif %}+{% endif %}- <table class="bordered highlight responsive data-table">+<table class="bordered highlight responsive data-table"><tfoot>- <tr>- <td>- {% trans "Grand total" context "Order totals header" %}- </td>- <td>- {% gross order.get_total html=True %}- </td>- </tr>+ <tr>+ <td>+ {% trans "Grand total" context "Order totals header" %}+ </td>+ <td>+ {% gross order.get_total html=True %}+ </td>+ </tr></tfoot><tbody>- <tr>- <td class="wide">- {% trans "Subtotal" context "Order subtotal" %}- </td>- <td class="right-align">- {% gross order.get_subtotal_without_voucher html=True %}- </td>- </tr>+ <tr>+ <td class="wide">+ {% trans "Subtotal" context "Order subtotal" %}+ </td>+ <td class="right-align">+ {% gross order.get_subtotal_without_voucher html=True %}+ </td>+ </tr>+ <tr>+ <td>+ {% trans "Total Shipping Price" context "Order totals header" %}+ </td>+ <td class="right-align">+ {% gross order.get_total_shipping html=True %}+ </td>+ </tr>+ {% if order.discount_amount.gross %}<tr><td>- {% trans "Total Shipping Price" context "Order totals header" %}+ <a class="dropdown-button" href="#" data-activates="voucher-actions"+ data-constrainwidth="false">+ {% blocktrans trimmed with voucher=order.discount_name context "Order totals header" %}+ Voucher {{ voucher }}+ {% endblocktrans %}+ <svg data-src="{% static "dashboard/images/arrow_drop_down.svg" %}"/>+ </a>+ <ul id="voucher-actions" class="dropdown-content">+ <li>+ <a href="#base-modal"+ data-href="{% url 'dashboard:order-remove-voucher' order_pk=order.pk %}"+ class="modal-trigger-custom"+ title="{% trans "Remove voucher" context "Order totals action" %}">+ {% trans "Remove voucher" context "Order totals action" %}+ </a>+ </li>+ </ul></td><td class="right-align">- {% gross order.get_total_shipping html=True %}+ {% gross order.discount|discount_amount_for:order.total html=True %}</td></tr>- {% if order.discount_amount.gross %}- <tr>- <td>- <a class="dropdown-button" href="#" data-activates="voucher-actions" data-constrainwidth="false">- {% blocktrans trimmed with voucher=order.discount_name context "Order totals header" %}- Voucher {{ voucher }}- {% endblocktrans %}- <svg data-src="{% static "dashboard/images/arrow_drop_down.svg" %}" />- </a>- <ul id="voucher-actions" class="dropdown-content">- <li>- <a href="#base-modal" data-href="{% url 'dashboard:order-remove-voucher' order_pk=order.pk %}"- class="modal-trigger-custom" title="{% trans "Remove voucher" context "Order totals action" %}">- {% trans "Remove voucher" context "Order totals action" %}- </a>- </li>- </ul>- </td>- <td class="right-align">- {% gross order.discount|discount_amount_for:order.total html=True %}- </td>- </tr>{% endif %}</tbody></table>+diff --git a/templates/dashboard/order/pdf/packing_slip.html b/templates/dashboard/order/pdf/packing_slip.htmlindex 4c08735a0c..4c4d662bae 100644--- a/templates/dashboard/order/pdf/packing_slip.html+++ b/templates/dashboard/order/pdf/packing_slip.html@@ -2,95 +2,126 @@{% 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>+<style>+ {{ style }}+ html, body {+ font-size: 12px;+ }++ .order-table {+ margin-bottom: 30px;+ }++ .data-table {+ max-width: 100%;+ width: 100%;+ }++ .data-table tr {+ border-bottom: 1px #d0d0d0 solid;+ }++ .data-table tr:last-child {+ border-bottom: none;+ }++ .data-table td {+ height: 30px;+ padding: 10px;+ }++ header {+ margin-bottom: 5rem;+ }-<h2>{% trans "Company Details" context "Order invoice" %}</h2>-<table width="100%" border="1" cellspacing="0" cellpadding="10">-<tr>+ #invoice-footer {+ position: fixed;+ bottom: 0;+ width: 100%;+ text-align: center;+ }++ @page {+ @bottom-center {+ content: "Saleor eCommerce, Mirumee Software";+ }+ @bottom-right {+ content: "Page " counter(page) "/" counter(pages);+ }+ }+</style>++<header>+ <div style="float:left">+ <img src="{{ logo|safe }}">+ </div>+ <div+ style="float:right">{{ order.created }}<br>{% trans "Order ID:" %} {{ order.id }}+ </div>+</header>++<h2>{% trans "Packing Slips" %}</h2>+<table width="100%" border="1" cellspacing="0">+ <thead>+ <tr><th align="left" width="50%">{% trans "Shipping Details" %}</th><th align="left" width="50%">{% trans "Billing Details" %}</th>-</tr>-<tr>+ </tr>+ </thead>+ <tbody>+ <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>+ {% with order.shipping_address as address %}+ <h2>+ {% trans "Shipping address" context "" %}+ </h2>+ {% include 'dashboard/includes/_address.html' with address=address only %}+ {% endwith %}</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>+ {% with order.billing_address as address %}+ <h2>+ {% trans "Billing address" context "" %}+ </h2>+ {% include 'dashboard/includes/_address.html' with address=address only %}+ {% endwith %}</td>-</tr>+ </tr>+ </tbody></table><h2>{% trans "Items Ordered" context "Order invoice" %}</h2>- {% if group %}- <table class="bordered highlight responsive data-table">+{% if group %}+ <table class="bordered data-table"><thead>+ <tr>+ <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>- <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>+ <td>+ {{ item.product_name }}<br>+ </td>+ <td>+ {{ item.product_sku }}+ </td>+ <td class="right-align">+ {{ item.quantity }}+ </td></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 %}+ {% endfor %}</tbody></table>- {% endif %}+{% endif %}+-</table>