Skip to content

Commit

Permalink
Merge pull request #3526 from NyanKiyoshi/fix/pdf-footers
Browse files Browse the repository at this point in the history
Fix hard-coded site name in order PDFs
  • Loading branch information
maarcingebala committed Jan 2, 2019
2 parents a755c05 + c075718 commit 9cc6cbe
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 222 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ All notable, unreleased changes to this project will be documented in this file.
- Expand payment section in order view - #3502 by @dominik-zeglen
- Fixed migrations for default currency - #3235 by @bykof
- Filter attributes by collection in API - #3508 by @maarcingebala
- Fixed hard-coded site name in order PDFs - #3526 by @NyanKiyoshi
10 changes: 8 additions & 2 deletions saleor/dashboard/order/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf import settings
from django.contrib.sites.models import Site
from django.contrib.sites.shortcuts import get_current_site
from django.template.loader import get_template

Expand Down Expand Up @@ -31,14 +32,19 @@ def _create_pdf(rendered_template, absolute_url):


def create_invoice_pdf(order, absolute_url):
ctx = {'order': order}
ctx = {
'order': order,
'site': Site.objects.get_current()}
rendered_template = get_template(INVOICE_TEMPLATE).render(ctx)
pdf_file = _create_pdf(rendered_template, absolute_url)
return pdf_file, order


def create_packing_slip_pdf(order, fulfillment, absolute_url):
ctx = {'order': order, 'fulfillment': fulfillment}
ctx = {
'order': order,
'fulfillment': fulfillment,
'site': Site.objects.get_current()}
rendered_template = get_template(PACKING_SLIP_TEMPLATE).render(ctx)
pdf_file = _create_pdf(rendered_template, absolute_url)
return pdf_file, order
Expand Down
10 changes: 0 additions & 10 deletions saleor/static/dashboard/scss/document.scss
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,3 @@ table {
color: rgba(0, 0, 0, 0.87);
}
}

@page {
@bottom-center {
content: "Saleor eCommerce, Mirumee Software";
}

@bottom-right {
content: "Page " counter(page) "/" counter(pages);
}
}
42 changes: 42 additions & 0 deletions templates/dashboard/order/pdf/base_pdf.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% load i18n static %}
{% load price from taxed_prices %}
{% load discount_as_negative from voucher %}
{% load render_bundle from webpack_loader %}

<html lang="{{ LANGUAGE_CODE }}">
<head>
<title>{% block title %}{% endblock %}</title>
{% render_bundle "document" "css" %}
<style>
@page {
@bottom-center {
content: "{{ site.name }}";
}

@bottom-right {
content:
{% blocktrans trimmed context "Order PDF footer page counter" %}
"Page " counter(page) "/" counter(pages)
{% endblocktrans %};
}
}
</style>
</head>

<body>
<header>
<div style="float: left">
<img alt="logo" src="{% static "images/logo-document.svg" %}" />
</div>

<div style="float: right">
{{ order.created }}<br />
{% blocktrans trimmed context "Order PDF header" with order_id=order.id %}
Order #{{ order_id }}
{% endblocktrans %}
</div>
</header>

{% block content %}{% endblock %}
</body>
</html>
261 changes: 127 additions & 134 deletions templates/dashboard/order/pdf/invoice.html
Original file line number Diff line number Diff line change
@@ -1,158 +1,151 @@
{% extends "dashboard/order/pdf/base_pdf.html" %}

{% load i18n static %}
{% load price from taxed_prices %}
{% load discount_as_negative from voucher %}
{% load render_bundle from webpack_loader %}

<html>
<head>
<title>{% trans "Invoice for Order" context "Invoice title" %} #{{ order.id }}</title>
{% render_bundle 'document' 'css' %}
</head>
<body>
<header>
<div style="float:left">
<img src="{% static 'images/logo-document.svg' %}">
</div>
<div
style="float:right">{{ order.created }}<br>{% trans 'Order' context 'Invoice header' %} #{{ order.id }}
</div>
</header>

<h2>{% trans "Invoice" context "Order invoice" %}</h2>
<table width="100%" border="1" cellspacing="0">
<thead>
<tr>
{% if order.shipping_address %}
<th align="left" width="50%">
{% trans "Shipping address" context "Invoice shipping address" %}
</th>
{% endif %}
{% if order.billing_address %}
<th align="left" {% if order.shipping_address %} width="50%"{% endif %}>
{% trans "Billing address" context "Invoice billing address" %}
</th>
{% endif %}
</tr>
</thead>
<tbody>
<tr>
{% if order.shipping_address %}
<td>
{% include 'dashboard/includes/_address.html' with address=order.shipping_address only %}
</td>
{% endif %}
{% if order.billing_address %}
<td>
{% include 'dashboard/includes/_address.html' with address=order.billing_address only %}
</td>
{% endif %}
</tr>
</tbody>
</table>
{% block title %}
{% blocktrans trimmed context "Invoice title" with order_id=order.id %}
Invoice for Order #{{ order_id }}
{% endblocktrans %}
{% endblock %}

<h2>{% trans "Items Ordered" context "Invoice ordered items header" %}</h2>
{% if order %}
<table class="data-table order-table bordered">
{% block content %}
<h2>{% trans "Invoice" context "Order invoice" %}</h2>
<table width="100%" border="1" cellspacing="0">
<thead>
<tr>
<th>
<div class="wide">
{% trans "Item" context "Shipment order table header" %}
</div>
</th>
<th>
{% trans "SKU" context "Shipment order table header" %}
</th>
<th class="right-align">
{% trans "Tax rate" context "Shipment order table header" %}
</th>
<th class="right-align">
{% trans "Gross price" context "Shipment order table header" %}
</th>
<th class="right-align">
{% trans "Quantity" context "Shipment order table header" %}
</th>
<th class="right-align">
{% trans "Total" context "Shipment order table header" %}
</th>
{% if order.shipping_address %}
<th align="left" width="50%">
{% trans "Shipping address" context "Invoice shipping address" %}
</th>
{% endif %}
{% if order.billing_address %}
<th align="left" {% if order.shipping_address %} width="50%"{% endif %}>
{% trans "Billing address" context "Invoice billing address" %}
</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for line in order %}
<tr>
{% if order.shipping_address %}
<td>
{% include "dashboard/includes/_address.html" with address=order.shipping_address only %}
</td>
{% endif %}
{% if order.billing_address %}
<td>
{% include "dashboard/includes/_address.html" with address=order.billing_address only %}
</td>
{% endif %}
</tr>
</tbody>
</table>

<h2>{% trans "Items Ordered" context "Invoice ordered items header" %}</h2>
{% if order %}
<table class="data-table order-table bordered">
<thead>
<tr>
<th>
<div class="wide">
{% trans "Item" context "Shipment order table header" %}
</div>
</th>
<th>
{% trans "SKU" context "Shipment order table header" %}
</th>
<th class="right-align">
{% trans "Tax rate" context "Shipment order table header" %}
</th>
<th class="right-align">
{% trans "Gross price" context "Shipment order table header" %}
</th>
<th class="right-align">
{% trans "Quantity" context "Shipment order table header" %}
</th>
<th class="right-align">
{% trans "Total" context "Shipment order table header" %}
</th>
</tr>
</thead>
<tbody>
{% for line in order %}
<tr>
<td>
{{ line.product_name|truncatechars:30 }}<br>
</td>
<td>
{{ line.product_sku }}
</td>
<td class="right-align">
{% blocktrans with tax_rate=line.tax_rate context "Order line tax rate value" %}
{{ tax_rate }} %
{% endblocktrans %}
</td>
<td class="right-align">
{% price line.unit_price.gross %}
</td>
<td class="right-align">
{{ line.quantity }}
</td>
<td class="right-align">
{% price line.get_total.gross %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}

<table class="bordered highlight responsive data-table">
<tbody>
<tr>
<td class="wide">
{% trans "Subtotal" context "Order subtotal net price" %}
</td>
<td class="right-align">
{% price order.get_subtotal.gross %}
</td>
</tr>
<tr>
<td>
{% trans "Shipping" context "Order total shipping price header" %} {% if order.shipping_method_name %}({{ order.shipping_method_name }}){% endif %}
</td>
<td class="right-align">
{% price order.shipping_price.gross %}
</td>
</tr>
<tr>
<td>
{% trans "Total taxes (included)" context "Order total taxes header" %}
</td>
<td class="right-align">
{% price order.total.tax %}
</td>
</tr>
{% if order.discount_amount %}
<tr>
<td>
{{ line.product_name|truncatechars:30 }}<br>
</td>
<td>
{{ line.product_sku }}
</td>
<td class="right-align">
{% blocktrans with tax_rate=line.tax_rate context "Order line tax rate value" %}
{{ tax_rate }} %
{% endblocktrans %}
{% trans "Discount" context "Order voucher header" %} {% if order.discount_name %}({{ order.translated_discount_name|default:order.discount_name }}){% endif %}
</td>
<td class="right-align">
{% price line.unit_price.gross %}
</td>
<td class="right-align">
{{ line.quantity }}
</td>
<td class="right-align">
{% price line.get_total.gross %}
{% discount_as_negative order.discount_amount html=True %}
</td>
</tr>
{% endfor %}
{% endif %}
</tbody>
</table>
{% endif %}

<table class="bordered highlight responsive data-table">
<tbody>
<tr>
<td class="wide">
{% trans "Subtotal" context "Order subtotal net price" %}
</td>
<td class="right-align">
{% price order.get_subtotal.gross %}
</td>
</tr>
<tr>
<td>
{% trans "Shipping" context "Order total shipping price header" %} {% if order.shipping_method_name %}({{ order.shipping_method_name }}){% endif %}
</td>
<td class="right-align">
{% price order.shipping_price.gross %}
</td>
</tr>
<tr>
<td>
{% trans "Total taxes (included)" context "Order total taxes header" %}
</td>
<td class="right-align">
{% price order.total.tax %}
</td>
</tr>
{% if order.discount_amount %}
<tfoot>
<tr>
<td>
{% trans "Discount" context "Order voucher header" %} {% if order.discount_name %}({{ order.translated_discount_name|default:order.discount_name }}){% endif %}
{% trans "Grand total" context "Order total price header" %}
</td>
<td class="right-align">
{% discount_as_negative order.discount_amount html=True %}
{% price order.total.gross %}
</td>
</tr>
{% endif %}
</tbody>
<tfoot>
<tr>
<td>
{% trans "Grand total" context "Order total price header" %}
</td>
<td class="right-align">
{% price order.total.gross %}
</td>
</tr>
</tfoot>
</table>
</body>
</html>
</tfoot>
</table>
{% endblock %}

0 comments on commit 9cc6cbe

Please sign in to comment.