Skip to content

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

Add discount display templatetag

Krzysztof Wolski970f07da5396
diff --git a/saleor/discount/templatetags/__init__.py b/saleor/discount/templatetags/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/discount/templatetags/voucher.py b/saleor/discount/templatetags/voucher.py
new file mode 100644
index 0000000000..0a9d42410f
--- /dev/null
+++ b/saleor/discount/templatetags/voucher.py
@@ -0,0 +1,11 @@
+from django import template
+from django_prices.templatetags.prices_i18n import gross
+from prices import Price
+
+register = template.Library()
+
+
+def discount_as_negative(discount, html=False):
+ zero = Price(0, currency=discount.amount.currency)
+ return gross(zero-discount.amount, html=html)
diff --git a/templates/checkout/snippets/voucher-form.html b/templates/checkout/snippets/voucher-form.html
index e5d93d4ee8..0092da2d33 100644
--- a/templates/checkout/snippets/voucher-form.html
+++ b/templates/checkout/snippets/voucher-form.html
@@ -1,6 +1,7 @@
{% load bootstrap_field bootstrap_button bootstrap_icon from bootstrap3 %}
{% load trans from i18n %}
{% load gross from prices_i18n %}
+{% load discount_as_negative from voucher %}
{% if form %}
{% if discount %}
@@ -17,7 +18,7 @@
</form>
<div class="float-right">
- - {% gross discount.amount %}
+ {% discount_as_negative discount %}
</div>
{% else %}
<form action="{{ request.path }}?next={{ request.path }}"
diff --git a/templates/order/order-details.html b/templates/order/order-details.html
index 89d4811420..41601e8fc3 100644
--- a/templates/order/order-details.html
+++ b/templates/order/order-details.html
@@ -2,6 +2,7 @@
{% load gross from prices_i18n %}
{% load discount_amount_for from prices %}
{% load product_first_image from product_images %}
+{% load discount_as_negative from voucher %}
{% if order.user == user %}
@@ -71,7 +72,7 @@
<p>{{ order.discount_name }}</p>
</div>
<div class="col-4">
- <p class="float-right">{% gross order.discount|discount_amount_for:order.total %}</p>
+ <p class="float-right">{% discount_as_negative order.discount %}</p>
</div>
</div>
{% endif %}