Skip to content

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

Move taxed prices templatetags to core

Anna Siwike54994d24c9f
diff --git a/saleor/product/templatetags/price_ranges.py b/saleor/core/templatetags/taxed_prices.py
similarity index 70%
rename from saleor/product/templatetags/price_ranges.py
rename to saleor/core/templatetags/taxed_prices.py
index 113f91acb2..9cffd95aa0 100644
--- a/saleor/product/templatetags/price_ranges.py
+++ b/saleor/core/templatetags/taxed_prices.py
@@ -13,6 +13,16 @@ def price_range(context, price_range):
'display_gross_prices': display_gross_prices}
+def shipping_price_range(shipping_method, taxes):
+ """Return shipping price to display (gross or net) depending on settings.
+
+ Extra with_taxes param forces return of gross (if true)
+ or net (if false) price.
+ """
+ return shipping_method.get_price_range(taxes)
+
+
@register.simple_tag(takes_context=True)
def price_to_display(context, price, with_taxes=None):
"""Return price to display (gross or net) depending on settings.
@@ -27,11 +37,11 @@ def price_to_display(context, price, with_taxes=None):
return price.gross if display_gross_prices else price.net
-def tax_value(taxes, tax_rate):
+def tax_rate(taxes, rate_name):
"""Return tax rate value for given tax rate type in current country."""
if not taxes:
return 0
- tax = taxes.get(tax_rate) or taxes.get(DEFAULT_TAX_RATE_NAME)
+ tax = taxes.get(rate_name) or taxes.get(DEFAULT_TAX_RATE_NAME)
return tax['value']
diff --git a/saleor/shipping/models.py b/saleor/shipping/models.py
index 434b2a29bd..49d0d6dde5 100644
--- a/saleor/shipping/models.py
+++ b/saleor/shipping/models.py
@@ -39,10 +39,9 @@ class ShippingMethod(models.Model):
def countries(self):
return [str(country) for country in self.price_per_country.all()]
- @property
- def price_range(self):
+ def get_price_range(self, taxes=None):
prices = [
- country.get_total_price()
+ country.get_total_price(taxes)
for country in self.price_per_country.all()]
if prices:
return TaxedMoneyRange(min(prices), max(prices))
diff --git a/templates/_items.html b/templates/_items.html
index bf75ac0fc0..d67bfa39a0 100644
--- a/templates/_items.html
+++ b/templates/_items.html
@@ -1,6 +1,6 @@
{% load i18n %}
{% load staticfiles %}
-{% load price_range from price_ranges %}
+{% load price_range from taxed_prices %}
{% load product_first_image from product_images %}
{% load get_thumbnail from product_images %}
diff --git a/templates/cart/_subtotal_table.html b/templates/cart/_subtotal_table.html
index 2a32c4d159..7a3397cfce 100644
--- a/templates/cart/_subtotal_table.html
+++ b/templates/cart/_subtotal_table.html
@@ -1,5 +1,5 @@
{% load i18n %}
-{% load price_ranges %}
+{% load taxed_prices %}
{% load prices_i18n %}
{% if shipping_required %}
diff --git a/templates/cart/index.html b/templates/cart/index.html
index fb3fd6490e..47b2ce0fec 100644
--- a/templates/cart/index.html
+++ b/templates/cart/index.html
@@ -2,7 +2,7 @@
{% load i18n %}
{% load prices_i18n %}
{% load staticfiles %}
-{% load price_to_display from price_ranges %}
+{% load price_to_display from taxed_prices %}
{% load get_thumbnail from product_images %}
{% block title %}{% trans "Your cart" context "Cart page title" %} — {{ block.super }}{% endblock %}
diff --git a/templates/cart_dropdown.html b/templates/cart_dropdown.html
index c97b300561..11c4683563 100644
--- a/templates/cart_dropdown.html
+++ b/templates/cart_dropdown.html
@@ -3,7 +3,7 @@
{% load staticfiles %}
{% load get_thumbnail from product_images %}
{% load placeholder %}
-{% load price_to_display from price_ranges %}
+{% load price_to_display from taxed_prices %}
<div class="container">
{% if quantity > 0 %}
diff --git a/templates/checkout/details.html b/templates/checkout/details.html
index 473c2cee16..98c28a3478 100644
--- a/templates/checkout/details.html
+++ b/templates/checkout/details.html
@@ -2,7 +2,7 @@
{% load i18n %}
{% load prices_i18n %}
-{% load price_to_display from price_ranges %}
+{% load price_to_display from taxed_prices %}
{% load staticfiles %}
{% block title %}{% trans "Checkout" context "Checkout page title" %} — {{ block.super }}{% endblock %}
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index 6df01a6002..187a701805 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -3,7 +3,7 @@
{% load prices_i18n %}
{% load i18n %}
{% load i18n_address_tags %}
-{% load price_ranges %}
+{% load taxed_prices %}
{% load materializecss %}
{% load status %}
{% load staticfiles %}
diff --git a/templates/dashboard/order/modal/cancel_line.html b/templates/dashboard/order/modal/cancel_line.html
index d431d6836d..cf38429d82 100644
--- a/templates/dashboard/order/modal/cancel_line.html
+++ b/templates/dashboard/order/modal/cancel_line.html
@@ -3,7 +3,7 @@
{% load i18n %}
{% load materializecss %}
{% load prices_i18n %}
-{% load price_to_display from price_ranges %}
+{% load price_to_display from taxed_prices %}
{% block action_url %}
{% url 'dashboard:orderline-cancel' order_pk=order.pk line_pk=item.pk %}
diff --git a/templates/dashboard/product/detail.html b/templates/dashboard/product/detail.html
index 0a9edf7bb8..c2182cbbdf 100644
--- a/templates/dashboard/product/detail.html
+++ b/templates/dashboard/product/detail.html
@@ -2,7 +2,7 @@
{% load i18n %}
{% load prices_i18n %}
-{% load price_ranges %}
+{% load taxed_prices %}
{% load staticfiles %}
{% load status %}
{% load utils %}
@@ -100,7 +100,13 @@
<th>{% trans "SKU" %}</th>
<th>{% trans "Name" %}</th>
<th>{% trans "Status" %}</th>
- <th class="right-align">{% trans "Price" %}</th>
+ <th class="right-align">
+ {% if request.site.settings.include_taxes_in_prices %}
+ {% trans "Price (gross)" %}
+ {% else %}
+ {% trans "Price (net)" %}
+ {% endif %}
+ </th>
<th class="right-align">{% trans "Gross margin" %}</th>
{% if perms.product.edit_product %}
<th></th>
@@ -113,7 +119,12 @@
<td>{{ variant.sku }}</td>
<td>{{ variant }}</td>
<td class="wide">{% render_variant_availability_status variant %}</td>
- <td class="right-align">{{ variant.get_price.gross|amount }}</td>
+ <td class="right-align">
+ {% with request.site.settings.include_taxes_in_prices as display_gross_prices %}
+ {% price_to_display variant.get_price display_gross_prices as price %}
+ {{ price|amount }}
+ {% endwith %}
+ </td>
<td class="right-align">
{% margins_for_variant variant=variant as margins %}
{% if margins|length > 1 %}
@@ -162,31 +173,20 @@
</div>
</div>
<div class="data-table-container">
- <table class="data-table bordered highlight">
- <tbody>
- <tr>
- <td>
- {% trans "Sale price" context "Product field" %}
- </td>
- <td class="right-align">
- {% price_to_display sale_price.start as start_price %}
- {% price_to_display sale_price.stop as stop_price %}
-
- {% if start_price == stop_price %}
- {{ start_price|amount }}
- {% else %}
- {{ start_price|amount }} - {{ stop_price|amount }}
- {% endif %}
- </td>
- </tr>
- {% if discounted_price != sale_price %}
+ {% with request.site.settings.include_taxes_in_prices as display_gross_prices %}
+ <table class="data-table bordered highlight">
+ <tbody>
<tr>
<td>
- {% trans "Discounted price" context "Product field" %}
+ {% if display_gross_prices %}
+ {% trans "Sale price (gross)" context "Product field" %}
+ {% else %}
+ {% trans "Sale price (net)" context "Product field" %}
+ {% endif %}
</td>
<td class="right-align">
- {% price_to_display discounted_price.start as start_price %}
- {% price_to_display discounted_price.stop as stop_price %}
+ {% price_to_display sale_price.start display_gross_prices as start_price %}
+ {% price_to_display sale_price.stop display_gross_prices as stop_price %}
{% if start_price == stop_price %}
{{ start_price|amount }}
@@ -195,40 +195,61 @@
{% endif %}
</td>
</tr>
- {% endif %}
- <tr>
- <td>
- {% trans "Purchase cost" context "Product field" %}
- </td>
- <td class="right-align">
- {% price_to_display purchase_cost.start as start_price %}
- {% price_to_display purchase_cost.stop as stop_price %}
+ {% if discounted_price != sale_price %}
+ <tr>
+ <td>
+ {% if display_gross_prices %}
+ {% trans "Discounted price (gross)" context "Product field" %}
+ {% else %}
+ {% trans "Discounted price (net)" context "Product field" %}
+ {% endif %}
+ </td>
+ <td class="right-align">
+ {% price_to_display discounted_price.start display_gross_prices as start_price %}
+ {% price_to_display discounted_price.stop display_gross_prices as stop_price %}
- {% if start_price == stop_price %}
- {{ start_price|amount }}
- {% else %}
- {{ start_price|amount }} - {{ stop_price|amount }}
- {% endif %}
- </td>
- </tr>
- <tr>
- <td>
- {% trans "Gross margin" context "Product field" %}
- </td>
- <td class="right-align">
- {% if gross_margin %}
- {% if gross_margin.0 == gross_margin.1 %}
- {{ gross_margin.0 }}%
+ {% if start_price == stop_price %}
+ {{ start_price|amount }}
+ {% else %}
+ {{ start_price|amount }} - {{ stop_price|amount }}
+ {% endif %}
+ </td>
+ </tr>
+ {% endif %}
+ <tr>
+ <td>
+ {% trans "Purchase cost" context "Product field" %}
+ </td>
+ <td class="right-align">
+ {% price_to_display purchase_cost.start display_gross_prices as start_price %}
+ {% price_to_display purchase_cost.stop display_gross_prices as stop_price %}
+
+ {% if start_price == stop_price %}
+ {{ start_price|amount }}
+ {% else %}
+ {{ start_price|amount }} - {{ stop_price|amount }}
+ {% endif %}
+ </td>
+ </tr>
+ <tr>
+ <td>
+ {% trans "Gross margin" context "Product field" %}
+ </td>
+ <td class="right-align">
+ {% if gross_margin %}
+ {% if gross_margin.0 == gross_margin.1 %}
+ {{ gross_margin.0 }}%
+ {% else %}
+ {{ gross_margin.0 }}% - {{ gross_margin.1 }}%
+ {% endif %}
{% else %}
- {{ gross_margin.0 }}% - {{ gross_margin.1 }}%
+ -
{% endif %}
- {% else %}
- -
- {% endif %}
- </td>
- </tr>
- </tbody>
- </table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ {% endwith %}
</div>
</div>
</div>
diff --git a/templates/dashboard/shipping/list.html b/templates/dashboard/shipping/list.html
index dd768246b5..f4d7fcbcff 100644
--- a/templates/dashboard/shipping/list.html
+++ b/templates/dashboard/shipping/list.html
@@ -4,6 +4,7 @@
{% load status %}
{% load utils %}
{% load static %}
+{% load taxed_prices %}
{% block title %}
{% trans "Shipping methods" context "Dashboard shipping methods list" %} - {{ block.super }}
@@ -43,6 +44,9 @@
{% trans "Name" context "Shipping methods table header" as label %}
{% sorting_header 'name' label is_wide=True %}
+ <th>
+ {% trans "Price range (debug)" context "Shipping methods table header" %}
+ </th>
<th>
{% trans "Price range" context "Shipping methods table header" %}
</th>
@@ -58,12 +62,34 @@
{{ method }}
</td>
<td>
- {% if not method.price_range %}
+ {% if not method.get_price_range %}
-
- {% elif method.price_range.start == method.price_range.stop %}
- {{ method.price_range.start.gross|amount:'html' }}
{% else %}
- {{ method.price_range.start.gross|amount:'html' }}&ndash;{{ method.price_range.stop.gross|amount:'html' }}
+ {% with request.site.settings.include_taxes_in_prices as display_gross_prices %}
+ {% shipping_price_range method request.taxes as price_range %}
+
+ ({{ price_range.start.net|amount:'html' }} + {{ price_range.start.tax|amount:'html' }} VAT)
+ {% if price_range.start != price_range.stop %}
+ - ({{ price_range.stop.net|amount:'html' }} + {{ price_range.stop.tax|amount:'html' }} VAT)
+ {% endif %}
+ {% endwith %}
+ {% endif %}
+ </td>
+ <td>
+ {% if not method.get_price_range %}
+ -
+ {% else %}
+ {% with request.site.settings.include_taxes_in_prices as display_gross_prices %}
+ {% shipping_price_range method request.taxes as price_range %}
+ {% price_to_display price_range.start display_gross_prices as start_price %}
+ {% price_to_display price_range.stop display_gross_prices as stop_price %}
+
+ {% if start_price == stop_price %}
+ {{ start_price|amount }}
+ {% else %}
+ {{ start_price|amount }} - {{ stop_price|amount }}
+ {% endif %}
+ {% endwith %}
{% endif %}
</td>
<td>
diff --git a/templates/order/_ordered_items_table.html b/templates/order/_ordered_items_table.html
index a404535ac7..74e71aeee1 100644
--- a/templates/order/_ordered_items_table.html
+++ b/templates/order/_ordered_items_table.html
@@ -3,7 +3,7 @@
{% load amount from prices_i18n %}
{% load product_first_image from product_images %}
{% load discount_as_negative from voucher %}
-{% load price_ranges %}
+{% load taxed_prices %}
{% load placeholder %}
{% if order.user == user %}
diff --git a/templates/product/_items.html b/templates/product/_items.html
index 664dba49f2..ceb4979277 100644
--- a/templates/product/_items.html
+++ b/templates/product/_items.html
@@ -1,6 +1,6 @@
{% load i18n %}
{% load staticfiles %}
-{% load price_range from price_ranges %}
+{% load taxed_prices %}
{% load product_first_image from product_images %}
{% load get_thumbnail from product_images %}
{% load placeholder %}
diff --git a/templates/product/details.html b/templates/product/details.html
index 2303ce8b00..4aa3fcac92 100644
--- a/templates/product/details.html
+++ b/templates/product/details.html
@@ -4,7 +4,7 @@
{% load i18n %}
{% load markdown from markdown %}
{% load prices_i18n %}
-{% load price_ranges %}
+{% load taxed_prices %}
{% load staticfiles %}
{% load get_thumbnail product_first_image from product_images %}
{% load build_absolute_uri from urls %}
@@ -144,7 +144,7 @@
</small>
{% endif %}
<small>
- {% tax_value request.taxes product.tax_rate as tax_rate %}
+ {% tax_rate request.taxes product.tax_rate as tax_rate %}
{% if request.site.settings.display_gross_prices %}
{% blocktrans trimmed with tax_rate=tax_rate context "Product details page vat rate value" %}
including {{ tax_rate }}% VAT