Skip to content

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

Use price templatetag everywhere

Anna Siwik9c10d0a12330
diff --git a/saleor/core/templatetags/taxed_prices.py b/saleor/core/templatetags/taxed_prices.py
index e2b10ff4a5..bf90d84b2c 100644
--- a/saleor/core/templatetags/taxed_prices.py
+++ b/saleor/core/templatetags/taxed_prices.py
@@ -25,18 +25,19 @@ def tax_rate(taxes, rate_name):
@register.inclusion_tag('price.html', takes_context=True)
-def price(context, base, display_gross=None):
- if display_gross is None:
- display_gross = context['site'].settings.display_gross_prices
+def price(context, base, display_gross=None, html=True):
+ if isinstance(base, (TaxedMoney, TaxedMoneyRange)):
+ if display_gross is None:
+ display_gross = context['site'].settings.display_gross_prices
- if isinstance(base, TaxedMoneyRange):
- if display_gross:
- base = MoneyRange(start=base.start.gross, stop=base.stop.gross)
- else:
- base = MoneyRange(start=base.start.net, stop=base.stop.net)
+ if isinstance(base, TaxedMoneyRange):
+ if display_gross:
+ base = MoneyRange(start=base.start.gross, stop=base.stop.gross)
+ else:
+ base = MoneyRange(start=base.start.net, stop=base.stop.net)
- if isinstance(base, TaxedMoney):
- base = base.gross if display_gross else base.net
+ if isinstance(base, TaxedMoney):
+ base = base.gross if display_gross else base.net
is_range = isinstance(base, MoneyRange)
- return {'price': base, 'is_range': is_range}
+ return {'price': base, 'is_range': is_range, 'html': html}
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 4fed827281..1d6eacc315 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -11,6 +11,7 @@ from django_prices.templatetags import prices_i18n
from . import forms
from ...core.utils import get_paginator_items
+from ...discount.models import Sale
from ...product.models import (
AttributeChoiceValue, Product, ProductAttribute, ProductImage, ProductType,
ProductVariant)
@@ -184,7 +185,7 @@ def product_details(request, pk):
product, discounts=request.discounts, taxes=request.taxes)
sale_price = availability.price_range_undiscounted
discounted_price = availability.price_range
- purchase_cost, gross_margin = get_product_costs_data(product)
+ purchase_cost, margin = get_product_costs_data(product)
# no_variants is True for product types that doesn't require variant.
# In this case we're using the first variant under the hood to allow stock
@@ -197,7 +198,7 @@ def product_details(request, pk):
'discounted_price': discounted_price, 'variants': variants,
'images': images, 'no_variants': no_variants,
'only_variant': only_variant, 'purchase_cost': purchase_cost,
- 'gross_margin': gross_margin, 'is_empty': not variants.exists(),
+ 'margin': margin, 'is_empty': not variants.exists(),
'include_taxes_in_prices': include_taxes_in_prices}
return TemplateResponse(request, 'dashboard/product/detail.html', ctx)
@@ -385,9 +386,12 @@ def variant_details(request, product_pk, variant_pk):
images = variant.images.all()
margin = get_margin_for_variant(variant)
+ include_taxes_in_prices = request.site.settings.include_taxes_in_prices
+ discounted_price = variant.get_price(discounts=Sale.objects.all()).gross
ctx = {
- 'images': images, 'product': product,
- 'variant': variant, 'margin': margin}
+ 'images': images, 'product': product, 'variant': variant,
+ 'margin': margin, 'discounted_price': discounted_price,
+ 'include_taxes_in_prices': include_taxes_in_prices}
return TemplateResponse(
request,
'dashboard/product/product_variant/detail.html',
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
index c63c7d3e04..d75eebcaf3 100644
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -31,7 +31,7 @@ def resolve_attribute_list(attributes):
return attribute_list
-class GrossMargin(graphene.ObjectType):
+class Margin(graphene.ObjectType):
start = graphene.Int()
stop = graphene.Int()
@@ -107,7 +107,7 @@ class Product(CountableDjangoObjectType):
SelectedAttribute,
description='List of product attributes assigned to this product.')
purchase_cost = graphene.Field(MoneyRange)
- gross_margin = graphene.List(GrossMargin)
+ margin = graphene.List(Margin)
class Meta:
description = """Represents an individual item for sale in the
@@ -138,9 +138,9 @@ class Product(CountableDjangoObjectType):
return purchase_cost
@permission_required('product.view_product')
- def resolve_gross_margin(self, info):
- _, gross_margin = get_product_costs_data(self)
- return [GrossMargin(gross_margin[0], gross_margin[1])]
+ def resolve_margin(self, info):
+ _, margin = get_product_costs_data(self)
+ return [Margin(margin[0], margin[1])]
class ProductType(CountableDjangoObjectType):
diff --git a/saleor/product/utils/costs.py b/saleor/product/utils/costs.py
index b0edeeb544..b3bdd95af9 100644
--- a/saleor/product/utils/costs.py
+++ b/saleor/product/utils/costs.py
@@ -7,10 +7,10 @@ from ...core.utils import ZERO_TAXED_MONEY
def get_product_costs_data(product):
purchase_costs_range = MoneyRange(
start=ZERO_TAXED_MONEY, stop=ZERO_TAXED_MONEY)
- gross_margin = (0, 0)
+ margin = (0, 0)
if not product.variants.exists():
- return purchase_costs_range, gross_margin
+ return purchase_costs_range, margin
variants = product.variants.all()
costs_data = get_cost_data_from_variants(variants)
@@ -18,8 +18,8 @@ def get_product_costs_data(product):
purchase_costs_range = MoneyRange(
min(costs_data.costs), max(costs_data.costs))
if costs_data.margins:
- gross_margin = (costs_data.margins[0], costs_data.margins[-1])
- return purchase_costs_range, gross_margin
+ margin = (costs_data.margins[0], costs_data.margins[-1])
+ return purchase_costs_range, margin
class CostsData:
diff --git a/templates/account/details.html b/templates/account/details.html
index 832ccaf6ec..06401b6906 100644
--- a/templates/account/details.html
+++ b/templates/account/details.html
@@ -1,11 +1,12 @@
{% extends "base.html" %}
+{% load bootstrap_form from bootstrap4 %}
+{% load bootstrap_pagination from bootstrap4 %}
{% load i18n %}
{% load i18n_address_tags %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
{% load staticfiles %}
{% load status %}
-{% load bootstrap_form from bootstrap4 %}
-{% load bootstrap_pagination from bootstrap4 %}
{% block title %}{% trans "Your profile" context "User profile page title" %} — {{ block.super }}{% endblock %}
@@ -76,7 +77,7 @@
</div>
<div class="col-md-2 col-4">
<span class="float-right">
- {{ order.total.gross|amount:'html' }}
+ {% price order.total.gross %}
</span>
<br>
({{ order.total.net|amount:'html' }} + {{ order.total.tax|amount:'html' }} VAT)
diff --git a/templates/cart/_subtotal_table.html b/templates/cart/_subtotal_table.html
index dde62aa396..ba22a95b56 100644
--- a/templates/cart/_subtotal_table.html
+++ b/templates/cart/_subtotal_table.html
@@ -1,4 +1,5 @@
{% load i18n %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
{% load taxed_prices %}
@@ -9,7 +10,7 @@
<h3>{% trans "Subtotal" context "Order subtotal" %}</h3>
</div>
<div class="col-4">
- <h3 class="text-right cart-subtotal" data-value="{{ cart_total.gross|amount }}" {% if local_cart_total is not None %}data-value-local="{{ local_cart_total.gross|amount }}"{% endif %}>
+ <h3 class="text-right cart-subtotal" data-value="{% price cart_total.gross html=False %}" {% if local_cart_total is not None %}data-value-local="{% price local_cart_total.gross html=False %}"{% endif %}>
{% spaceless %}
{% price cart_total %}
<br>
diff --git a/templates/checkout/details.html b/templates/checkout/details.html
index bec956449f..4ed502fa0c 100644
--- a/templates/checkout/details.html
+++ b/templates/checkout/details.html
@@ -1,9 +1,9 @@
{% extends "base.html" %}
{% load i18n %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
{% load staticfiles %}
-{% load price from taxed_prices %}
{% block title %}{% trans "Checkout" context "Checkout page title" %} — {{ block.super }}{% endblock %}
@@ -94,7 +94,7 @@
{% endif %}
</div>
<div class="col-4">
- <p class="float-right">{{ total.tax|amount:'html' }}</p>
+ <p class="float-right">{% price total.tax %}</p>
</div>
</div>
<div class="row checkout__review__section">
@@ -108,7 +108,7 @@
<h3>{% trans "Total" context "Order review section title" %}</h3>
</div>
<div class="col-4">
- <h3 class="float-right">{{ total.gross|amount:'html' }}</h3>
+ <h3 class="float-right">{% price total.gross %}</h3>
</div>
<div class="col-md-12">
<p class="small text-right">
diff --git a/templates/dashboard/customer/detail.html b/templates/dashboard/customer/detail.html
index e60860c02f..b0fa0d8a7e 100644
--- a/templates/dashboard/customer/detail.html
+++ b/templates/dashboard/customer/detail.html
@@ -1,9 +1,10 @@
{% extends "dashboard/base.html" %}
-{% load prices_i18n %}
{% load i18n %}
{% load materializecss %}
-{% load status %}
+{% load price from taxed_prices %}
+{% load prices_i18n %}
{% load staticfiles %}
+{% load status %}
{% block title %}
{{ customer }} - {% trans "Customers" context "Dashboard customers list" %} - {{ block.super }}
@@ -121,7 +122,7 @@
{% render_order_status order.status order.get_status_display %}
</td>
<td class="right-align">
- {{ order.total.gross|amount:'html' }}
+ {% price order.total.gross %}
</td>
</tr>
{% endfor %}
diff --git a/templates/dashboard/discount/voucher/list.html b/templates/dashboard/discount/voucher/list.html
index 4d79a1ae11..e50f8c3055 100644
--- a/templates/dashboard/discount/voucher/list.html
+++ b/templates/dashboard/discount/voucher/list.html
@@ -1,5 +1,6 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
{% load materializecss %}
{% load utils %}
@@ -92,7 +93,7 @@
</td>
<td class="right-align">
{% if voucher.limit %}
- {{ voucher.limit|amount:'html' }}
+ {% price voucher.limit %}
{% else %}
-
{% endif %}
diff --git a/templates/dashboard/index.html b/templates/dashboard/index.html
index 3fa90c15f4..e0f58d96d6 100644
--- a/templates/dashboard/index.html
+++ b/templates/dashboard/index.html
@@ -1,5 +1,6 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
{% load status %}
@@ -48,7 +49,7 @@
{{ payment.order.user|default:_("Guest") }}
</td>
<td class="right-align">
- {{ payment.get_total_price.gross|amount:'html' }}
+ {% price payment.get_total_price.gross %}
</td>
</tr>
{% endfor %}
@@ -113,7 +114,7 @@
{% render_status order.get_last_payment_status order.get_last_payment_status_display %}
</td>
<td class="right-align">
- {{ order.total.gross|amount:'html' }}
+ {% price order.total.gross %}
</td>
</tr>
{% endfor %}
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index a053bffa4f..b54e95a3e5 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -130,7 +130,7 @@
</td>
<td class="right-align">
<strong>
- {{ balance.gross|amount:'html' }}
+ {% price balance.gross %}
</strong>
</td>
</tr>
@@ -142,7 +142,7 @@
</td>
<td class="right-align">
{% if preauthorized.gross %}
- {{ preauthorized.gross|amount:'html' }}
+ {% price preauthorized.gross %}
{% else %}
{% trans "N/A" context "Preauthorized amount not available" %}
{% endif %}
@@ -153,7 +153,7 @@
{% trans "Captured amount" context "Order summary card header" %}
</td>
<td class="right-align">
- {{ captured.gross|amount:'html' }}
+ {% price captured.gross %}
</td>
</tr>
</tbody>
@@ -442,11 +442,11 @@
<p>
({{ order.shipping_price.net|amount:'html' }} + {{ order.shipping_price.tax|amount:'html' }} VAT)
</p>
- <p>{{ order.total.tax|amount:'html' }}</p>
+ <p>{% price order.total.tax %}</p>
{% if order.is_draft or order.discount_amount %}
<p>{% discount_as_negative order.discount_amount html=True %}</p>
{% endif %}
- <p><strong>{{ order.total.gross|amount:'html' }}</strong></p>
+ <p><strong>{% price order.total.gross %}</strong></p>
<p>
<strong>({{ order.total.net|amount:'html' }} + {{ order.total.tax|amount:'html' }} VAT)</strong>
</p>
diff --git a/templates/dashboard/order/list.html b/templates/dashboard/order/list.html
index 02b882d589..034401d974 100644
--- a/templates/dashboard/order/list.html
+++ b/templates/dashboard/order/list.html
@@ -1,5 +1,6 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
{% load status %}
{% load utils %}
@@ -83,7 +84,7 @@
({{ order.total.net|amount:'html' }} + {{ order.total.tax|amount:'html' }} VAT)
</td>
<td class="right-align">
- {{ order.total.gross|amount:'html' }}
+ {% price order.total.gross %}
</td>
</tr>
{% endfor %}
diff --git a/templates/dashboard/order/modal/capture.html b/templates/dashboard/order/modal/capture.html
index 9aeba9051a..dc28ecd153 100644
--- a/templates/dashboard/order/modal/capture.html
+++ b/templates/dashboard/order/modal/capture.html
@@ -1,8 +1,9 @@
{% extends "dashboard/base_modal.html" %}
-{% load i18n %}
{% load babel %}
+{% load i18n %}
{% load materializecss %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
{% block action_url %}
@@ -19,10 +20,10 @@
{% trans "Before this action:" context "Modal capture payment title" %}
<ul class="list">
<li class="list-item">{% trans "Order total:" context "Modal capture payment list title" %}
- {{ payment.order.total.gross|amount:'html' }}
+ {% price payment.order.total.gross %}
</li>
<li class="list-item">{% trans "Taxes (included):" context "Modal capture payment list title" %}
- {{ payment.order.total.tax|amount:'html' }}
+ {% price payment.order.total.tax %}
</li>
<li class="list-item">{% trans "Captured amount:" context "Modal capture payment list title" %}
{{ captured|currencyfmt:currency }}
diff --git a/templates/dashboard/order/modal/mark_as_paid.html b/templates/dashboard/order/modal/mark_as_paid.html
index 3dcf241800..e8ab5f4731 100644
--- a/templates/dashboard/order/modal/mark_as_paid.html
+++ b/templates/dashboard/order/modal/mark_as_paid.html
@@ -2,6 +2,7 @@
{% load i18n %}
{% load materializecss %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
{% block action_url %}
@@ -15,7 +16,7 @@
{% block content %}
<div class="col s12">
{% trans "Are you sure you want mark order as paid?" context "Modal mark order as paid text" %}
- </br>{% trans "Total received:" context "Modal mark order as paid text" %} {{ order.total.gross|amount:'html' }}
+ </br>{% trans "Total received:" context "Modal mark order as paid text" %} {% price order.total.gross %}
</div>
{% endblock %}
diff --git a/templates/dashboard/order/modal/refund.html b/templates/dashboard/order/modal/refund.html
index 05b068cf48..8fa0964cf7 100644
--- a/templates/dashboard/order/modal/refund.html
+++ b/templates/dashboard/order/modal/refund.html
@@ -1,8 +1,9 @@
{% extends "dashboard/base_modal.html" %}
-{% load i18n %}
{% load babel %}
+{% load i18n %}
{% load materializecss %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
@@ -20,10 +21,10 @@
{% trans "Before this action:" context "Modal refund payment title" %}
<ul class="list">
<li class="list-item">{% trans "Order total:" context "Modal refund payment list title" %}
- {{ payment.order.total.gross|amount:'html' }}
+ {% price payment.order.total.gross %}
</li>
<li class="list-item">{% trans "Taxes (included):" context "Modal refund payment list title" %}
- {{ payment.order.total.tax|amount:'html' }}
+ {% price payment.order.total.tax %}
</li>
<li class="list-item">{% trans "Captured amount:" context "Modal refund payment list title" %}
{{ captured|currencyfmt:currency }}
diff --git a/templates/dashboard/order/pdf/invoice.html b/templates/dashboard/order/pdf/invoice.html
index 1486690c47..850b8ef98a 100644
--- a/templates/dashboard/order/pdf/invoice.html
+++ b/templates/dashboard/order/pdf/invoice.html
@@ -1,4 +1,5 @@
{% load i18n static %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
{% load discount_as_negative from voucher %}
{% load render_bundle from webpack_loader %}
@@ -92,13 +93,13 @@
{% endblocktrans %}
</td>
<td class="right-align">
- {{ line.unit_price.gross|amount:'html' }}
+ {% price line.unit_price.gross %}
</td>
<td class="right-align">
{{ line.quantity }}
</td>
<td class="right-align">
- {{ line.get_total.gross|amount:'html' }}
+ {% price line.get_total.gross %}
</td>
</tr>
{% endfor %}
@@ -110,26 +111,26 @@
<tbody>
<tr>
<td class="wide">
- {% trans "Subtotal net" context "Order subtotal net price" %}
+ {% trans "Subtotal" context "Order subtotal net price" %}
</td>
<td class="right-align">
- {{ order.get_subtotal.net|amount:'html' }}
+ {% price order.get_subtotal.gross %}
</td>
</tr>
<tr>
<td>
- {% trans "Total taxes" context "Order total taxes header" %}
+ {% trans "Shipping" context "Order total shipping price header" %} {% if order.shipping_method_name %}({{ order.shipping_method_name }}){% endif %}
</td>
<td class="right-align">
- {{ order.total.tax|amount:'html' }}
+ {% price order.shipping_price.gross %}
</td>
</tr>
<tr>
<td>
- {% trans "Shipping" context "Order total shipping price header" %} {% if order.shipping_method_name %}({{ order.shipping_method_name }}){% endif %}
+ {% trans "Total taxes (included)" context "Order total taxes header" %}
</td>
<td class="right-align">
- {{ order.shipping_price.gross|amount:'html' }}
+ {% price order.total.tax %}
</td>
</tr>
{% if order.discount_amount %}
@@ -149,7 +150,7 @@
{% trans "Grand total" context "Order total price header" %}
</td>
<td class="right-align">
- {{ order.total.gross|amount:'html' }}
+ {% price order.total.gross %}
</td>
</tr>
</tfoot>
diff --git a/templates/dashboard/product/detail.html b/templates/dashboard/product/detail.html
index eeecb60a86..ec353ee9a5 100644
--- a/templates/dashboard/product/detail.html
+++ b/templates/dashboard/product/detail.html
@@ -40,26 +40,28 @@
<span class="card-title">
{{ product }}
</span>
- <div class="row">
- <div class="col s12">
- <form id="toggle-publish-form" action="{% url 'dashboard:product-publish' product.pk %}">
- {% csrf_token %}
- <div class="switch" id="product-is-published">
- <label>
- <input id="toggle-publish-switch" type="checkbox" {% if product.is_published %} checked {% endif %}>
- <span class="lever"></span>
- <span class="label">
- {% if product.is_published %}
- {% trans "Published" context "Product field" %}
- {% else %}
- {% trans "Draft" context "Product field" %}
- {% endif %}
- </span>
- </label>
- </div>
- </form>
+ {% if perms.product.edit_product %}
+ <div class="row">
+ <div class="col s12">
+ <form id="toggle-publish-form" action="{% url 'dashboard:product-publish' product.pk %}">
+ {% csrf_token %}
+ <div class="switch" id="product-is-published">
+ <label>
+ <input id="toggle-publish-switch" type="checkbox" {% if product.is_published %} checked {% endif %}>
+ <span class="lever"></span>
+ <span class="label">
+ {% if product.is_published %}
+ {% trans "Published" context "Product field" %}
+ {% else %}
+ {% trans "Draft" context "Product field" %}
+ {% endif %}
+ </span>
+ </label>
+ </div>
+ </form>
+ </div>
</div>
- </div>
+ {% endif %}
<div class="row">
<div class="col s12">
<h5>{% render_availability_status product %}</h5>
@@ -102,9 +104,9 @@
<th>{% trans "Status" %}</th>
<th class="right-align">
{% if include_taxes_in_prices %}
- {% trans "Price (gross)" %}
+ {% trans "Gross price" %}
{% else %}
- {% trans "Price (net)" %}
+ {% trans "Net price" %}
{% endif %}
</th>
<th class="right-align">{% trans "Gross margin" %}</th>
@@ -120,7 +122,7 @@
<td>{{ variant }}</td>
<td class="wide">{% render_variant_availability_status variant %}</td>
<td class="right-align">
- {{ variant.base_price|amount:'html' }}
+ {% price variant.base_price %}
</td>
<td class="right-align">
{% margins_for_variant variant=variant as margins %}
@@ -147,90 +149,94 @@
</div>
{% endif %}
</div>
- {% if perms.product.edit_product %}
- <div class="col s12 l4">
- <div id="status">
- <div class="row no-margin">
- <div class="col s12">
- <div class="card">
- <div class="data-table-header">
- <div class="data-table-title">
- <h5>
- {% trans "Pricing" context "Product pricing card header" %}
- </h5>
- <h6>
- {% if product.charge_taxes %}
- {% blocktrans trimmed with tax_rate=product.tax_rate context "Product pricing card header subtitle" %}
- Taxes are charged ({{ tax_rate }} tax rate)
- {% endblocktrans %}
+ <div class="col s12 l4">
+ <div class="row no-margin">
+ <div class="col s12">
+ <div class="card">
+ <div class="data-table-header">
+ <div class="data-table-title">
+ <h5>
+ {% trans "Pricing" context "Product pricing card header" %}
+ </h5>
+ <h6>
+ {% if product.charge_taxes %}
+ {% blocktrans trimmed with tax_rate=product.tax_rate context "Product pricing card header subtitle" %}
+ Taxes are charged ({{ tax_rate }} tax rate)
+ {% endblocktrans %}
+ {% else %}
+ {% trans "Taxes are not charged" context "Product pricing card header subtitle" %}
+ {% endif %}
+ </h6>
+ </div>
+ </div>
+ <div class="data-table-container">
+ <table class="data-table bordered highlight">
+ <tbody>
+ <tr>
+ <td>
+ {% if include_taxes_in_prices %}
+ {% trans "Gross sale price" context "Product field" %}
{% else %}
- {% trans "Taxes are not charged" context "Product pricing card header subtitle" %}
+ {% trans "Net sale price" context "Product field" %}
{% endif %}
- </h6>
- </div>
- </div>
- <div class="data-table-container">
- <table class="data-table bordered highlight">
- <tbody>
- <tr>
- <td>
- {% if include_taxes_in_prices %}
- {% trans "Sale price (gross)" context "Product field" %}
- {% else %}
- {% trans "Sale price (net)" context "Product field" %}
- {% endif %}
- </td>
- <td class="right-align">
- {% price sale_price display_gross=include_taxes_in_prices %}
- </td>
- </tr>
- {% if discounted_price != sale_price %}
- <tr>
- <td>
- {% if include_taxes_in_prices %}
- {% trans "Discounted price (gross)" context "Product field" %}
- {% else %}
- {% trans "Discounted price (net)" context "Product field" %}
- {% endif %}
- </td>
- <td class="right-align">
- {% price discounted_price display_gross=include_taxes_in_prices %}
- </td>
- </tr>
+ </td>
+ <td class="right-align">
+ {% price sale_price display_gross=include_taxes_in_prices %}
+ </td>
+ </tr>
+ {% if discounted_price != sale_price %}
+ <tr>
+ <td>
+ {% if include_taxes_in_prices %}
+ {% trans "Gross discounted price" context "Product field" %}
+ {% else %}
+ {% trans "Net discounted price" context "Product field" %}
+ {% endif %}
+ </td>
+ <td class="right-align">
+ {% price discounted_price display_gross=include_taxes_in_prices %}
+ </td>
+ </tr>
+ {% endif %}
+ <tr>
+ <td>
+ {% if include_taxes_in_prices %}
+ {% trans "Gross purchase cost" context "Product field" %}
+ {% else %}
+ {% trans "Net purchase cost" context "Product field" %}
{% endif %}
- <tr>
- <td>
- {% trans "Purchase cost" context "Product field" %}
- </td>
- <td class="right-align">
- {% price purchase_cost %}
- </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 %}
- -
- {% endif %}
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
+ </td>
+ <td class="right-align">
+ {% price purchase_cost %}
+ </td>
+ </tr>
+ <tr>
+ <td>
+ {% if include_taxes_in_prices %}
+ {% trans "Gross margin" context "Product field" %}
+ {% else %}
+ {% trans "Net margin" context "Product field" %}
+ {% endif %}
+ </td>
+ <td class="right-align">
+ {% if margin %}
+ {% if margin.0 == margin.1 %}
+ {{ margin.0 }}%
+ {% else %}
+ {{ margin.0 }}% - {{ margin.1 }}%
+ {% endif %}
+ {% else %}
+ -
+ {% endif %}
+ </td>
+ </tr>
+ </tbody>
+ </table>
</div>
</div>
</div>
</div>
- {% endif %}
+ </div>
<div class="col s12 l4">
<div id="images">
<div class="row">
diff --git a/templates/dashboard/product/list.html b/templates/dashboard/product/list.html
index 06df47cabd..4f4cce833d 100644
--- a/templates/dashboard/product/list.html
+++ b/templates/dashboard/product/list.html
@@ -1,9 +1,10 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
-{% load prices_i18n %}
{% load materializecss %}
-{% load staticfiles %}
+{% load price from taxed_prices %}
+{% load prices_i18n %}
{% load product_first_image from product_images %}
+{% load staticfiles %}
{% load utils %}
{% block title %}
@@ -83,7 +84,7 @@
{{ product.name }}
</td>
<td>
- {{ product.price|amount:'html' }}
+ {% price product.price %}
</td>
</tr>
{% endfor %}
diff --git a/templates/dashboard/product/product_variant/detail.html b/templates/dashboard/product/product_variant/detail.html
index c285109e11..0047f10527 100644
--- a/templates/dashboard/product/product_variant/detail.html
+++ b/templates/dashboard/product/product_variant/detail.html
@@ -1,6 +1,7 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
{% load staticfiles %}
{% load status %}
@@ -43,56 +44,17 @@
{% block content %}
<div class="row">
- <div class="col m12 l9">
+ <div class="col m12 l8">
<div class="card">
<div class="card-content">
- <p class="card-title">{{ product }} <br> {% trans "SKU" context "Dashboard variant details view" %} {{ variant.sku }}</p>
- <p></p>
- <div class="row">
- <div class="col s5 m6">
- <p class="text-padding">{% trans "Sale price" context "Dashboard variant details view" %}</p>
- </div>
- <div class="col s7 m6">
- <p class="text-padding right-align">{{ variant.get_price.gross|amount }}</p>
- </div>
- <div class="col s5 m6">
- <p class="text-padding">{% trans "Cost price" context "Dashboard variant details view" %}</p>
- </div>
- <div class="col s7 m6">
- <p class="text-padding right-align">
- {% if variant.cost_price %}
- {{ variant.cost_price|amount}}
- {% else %}
- -
- {% endif %}
- </p>
- </div>
- <div class="col s5 m6">
- <p class="text-padding">{% trans "Gross margin" context "Dashboard variant details view" %}</p>
- </div>
- <div class="col s7 m6">
- <p class="text-padding right-align">
- {% if margin %}
- {{ margin }}%
- {% else %}
- -
- {% endif %}
- </p>
- </div>
+ <div class="card-title">
+ {{ product }}
+ <br>
+ {% trans "SKU" context "Dashboard variant details view" %} {{ variant.sku }}
</div>
- <br>
<div class="row">
- <div class="col s5 m6">
- <p class="text-padding">{% trans "Number in stock" context "Dashboard variant details view" %}</p>
- </div>
- <div class="col s7 m6">
- <p class="text-padding right-align">{{ variant.quantity }}</p>
- </div>
- <div class="col s5 m6">
- <p class="text-padding">{% trans "Allocated" context "Dashboard variant details view" %}</p>
- </div>
- <div class="col s7 m6">
- <p class="text-padding right-align">{{ variant.quantity_allocated }}</p>
+ <div class="col s12">
+ <h5>{% render_variant_availability_status variant %}</h5>
</div>
</div>
</div>
@@ -108,34 +70,137 @@
{% endif %}
</div>
</div>
- <div class="col m12 l3">
- <div class="card">
- <div class="card-content">
- <h5>{% render_variant_availability_status variant %}</h5>
- </div>
- </div>
- <div class="card">
- <div class="card-content">
- <span class="card-title">{% trans "Variant Images" context "Dashboard variant details view" %}</span>
- <div class="row">
- {% for image in images %}
- <div class="col s4">
- <img class="responsive-img" src="{{ image.image.crop.255x255 }}" srcset="{{ image.image.crop.255x255 }} 1x, {{ image.image.crop.510x510 }} 2x" alt="{{ image.alt }}">
+ <div class="col m12 l4">
+ <div class="row no-margin">
+ <div class="col s12">
+ <div class="card">
+ <div class="data-table-header">
+ <div class="data-table-title">
+ <h5>
+ {% trans "Pricing" context "Product pricing card header" %}
+ </h5>
</div>
- {% empty %}
- <div class="col s4">
- {% trans "No images" %}
</div>
- {% endfor %}
+ <div class="data-table-container">
+ <table class="data-table bordered highlight">
+ <tbody>
+ <tr>
+ <td>
+ {% if include_taxes_in_prices %}
+ {% trans "Gross sale price" context "Product field" %}
+ {% else %}
+ {% trans "Net sale price" context "Product field" %}
+ {% endif %}
+ </td>
+ <td class="right-align">
+ {% price variant.base_price %}
+ </td>
+ </tr>
+ {% if discounted_price != variant.base_price %}
+ <tr>
+ <td>
+ {% if include_taxes_in_prices %}
+ {% trans "Gross discounted price" context "Product field" %}
+ {% else %}
+ {% trans "Net discounted price" context "Product field" %}
+ {% endif %}
+ </td>
+ <td class="right-align">
+ {% price discounted_price %}
+ </td>
+ </tr>
+ {% endif %}
+ <tr>
+ <td>
+ {% if include_taxes_in_prices %}
+ {% trans "Gross purchase cost" context "Product field" %}
+ {% else %}
+ {% trans "Net purchase cost" context "Product field" %}
+ {% endif %}
+ </td>
+ <td class="right-align">
+ {% if variant.cost_price %}
+ {% price variant.cost_price %}
+ {% else %}
+ -
+ {% endif %}
+ </td>
+ </tr>
+ <tr>
+ <td>
+ {% if include_taxes_in_prices %}
+ {% trans "Gross margin" context "Product field" %}
+ {% else %}
+ {% trans "Net margin" context "Product field" %}
+ {% endif %}
+ </td>
+ <td class="right-align">
+ {% if margin %}
+ {{ margin }}%
+ {% else %}
+ -
+ {% endif %}
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
</div>
- </div>
- {% if perms.product.edit_product %}
- <div class="card-action">
- <a class="btn-flat waves-effect modal-trigger-custom" href="#base-modal" data-href="{% url 'dashboard:variant-images' product_pk=product.pk variant_pk=variant.pk %}">
- {% trans "Select images" context "Dashboard action" %}
- </a>
+ <div class="card">
+ <div class="data-table-header">
+ <div class="data-table-title">
+ <h5>
+ {% trans "Inventory" context "Product variant inventory card header" %}
+ </h5>
+ </div>
+ </div>
+ <div class="data-table-container">
+ <table class="data-table bordered highlight">
+ <tbody>
+ <tr>
+ <td>
+ {% trans "Number in stock" context "Dashboard variant details view" %}
+ </td>
+ <td class="right-align">
+ {{ variant.quantity }}
+ </td>
+ </tr>
+ <tr>
+ <td>
+ {% trans "Allocated" context "Dashboard variant details view" %}
+ </td>
+ <td class="right-align">
+ {{ variant.quantity_allocated }}
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
</div>
- {% endif %}
+ <div class="card">
+ <div class="card-content">
+ <span class="card-title">{% trans "Variant Images" context "Dashboard variant details view" %}</span>
+ <div class="row">
+ {% for image in images %}
+ <div class="col s4">
+ <img class="responsive-img" src="{{ image.image.crop.255x255 }}" srcset="{{ image.image.crop.255x255 }} 1x, {{ image.image.crop.510x510 }} 2x" alt="{{ image.alt }}">
+ </div>
+ {% empty %}
+ <div class="col s4">
+ {% trans "No images" %}
+ </div>
+ {% endfor %}
+ </div>
+ </div>
+ {% if perms.product.edit_product %}
+ <div class="card-action">
+ <a class="btn-flat waves-effect modal-trigger-custom" href="#base-modal" data-href="{% url 'dashboard:variant-images' product_pk=product.pk variant_pk=variant.pk %}">
+ {% trans "Select images" context "Dashboard action" %}
+ </a>
+ </div>
+ {% endif %}
+ </div>
+ </div>
</div>
</div>
</div>
diff --git a/templates/dashboard/search/results.html b/templates/dashboard/search/results.html
index 9a716334cd..a3a2790331 100644
--- a/templates/dashboard/search/results.html
+++ b/templates/dashboard/search/results.html
@@ -1,9 +1,10 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
-{% load prices_i18n %}
{% load materializecss %}
-{% load staticfiles %}
+{% load price from taxed_prices %}
+{% load prices_i18n %}
{% load product_first_image from product_images %}
+{% load staticfiles %}
{% block title %}
{% trans "Search results" context "Search page title" %} - {{ block.super }}
@@ -35,7 +36,7 @@
</span>
<p class="list-item-price">
<small>
- {{ product.price|amount:'html' }}
+ {% price product.price %}
</small>
</p>
</a>
diff --git a/templates/dashboard/shipping/detail.html b/templates/dashboard/shipping/detail.html
index b6f6bba7c5..8354739576 100644
--- a/templates/dashboard/shipping/detail.html
+++ b/templates/dashboard/shipping/detail.html
@@ -1,6 +1,7 @@
{% extends 'dashboard/base.html' %}
{% load i18n %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
{% load staticfiles %}
@@ -94,7 +95,7 @@
{% for country in method_countries %}
<tr>
<td>{{ country.get_country_code_display }}</td>
- <td>{{ country.price|amount:'html' }}</td>
+ <td>{% price country.price %}</td>
<td class="right-align">
<a href="{% url 'dashboard:shipping-method-country-edit' shipping_method_pk=shipping_method.pk country_pk=country.pk %}" class="btn-flat waves-effect">
{% trans 'Edit' context 'Attribute choice value edit action' %}
diff --git a/templates/order/_ordered_items_table.html b/templates/order/_ordered_items_table.html
index be5745faa4..103fc5141b 100644
--- a/templates/order/_ordered_items_table.html
+++ b/templates/order/_ordered_items_table.html
@@ -3,8 +3,8 @@
{% load i18n %}
{% load i18n_address_tags %}
{% load placeholder %}
-{% load product_first_image from product_images %}
{% load price from taxed_prices %}
+{% load product_first_image from product_images %}
{% if order.user == user %}
<div class="order-details__addresses">
@@ -144,7 +144,7 @@
</p>
</div>
<div class="col-4">
- <p class="float-right">{{ order.total.tax|amount:'html' }}</p>
+ <p class="float-right">{% price order.total.tax %}</p>
</div>
</div>
</div>
@@ -158,7 +158,7 @@
</div>
<div class="col-4">
<p class="float-right">
- {{ order.total.gross|amount:'html' }}
+ {% price order.total.gross %}
<br>
({{ order.total.net|amount:'html' }} + {{ order.total.tax|amount:'html' }} VAT)
</p>
diff --git a/templates/price.html b/templates/price.html
index 83301dc866..5ad8aa7e5b 100644
--- a/templates/price.html
+++ b/templates/price.html
@@ -1,11 +1,23 @@
-{% load prices_i18n %}
-
-{% if is_range %}
- {% if price.start == price.stop %}
- {{ price.start|amount }}
+{% load prices_i18n %}{% spaceless %}
+ {% if is_range %}
+ {% if price.start == price.stop %}
+ {% if html %}
+ {{ price.start|amount:'html' }}
+ {% else %}
+ {{ price.start|amount }}
+ {% endif %}
+ {% else %}
+ {% if html %}
+ {{ price.start|amount:'html' }} - {{ price.stop|amount:'html' }}
+ {% else %}
+ {{ price.start|amount }} - {{ price.stop|amount }}
+ {% endif %}
+ {% endif %}
{% else %}
- {{ price.start|amount }} - {{ price.stop|amount }}
+ {% if html %}
+ {{ price|amount:'html' }}
+ {% else %}
+ {{ price|amount }}
+ {% endif %}
{% endif %}
-{% else %}
- {{ price|amount }}
-{% endif %}
+{% endspaceless %}
diff --git a/templates/templated_email/source/order/confirm_order.email b/templates/templated_email/source/order/confirm_order.email
index 72fa40ef83..13fa46256e 100644
--- a/templates/templated_email/source/order/confirm_order.email
+++ b/templates/templated_email/source/order/confirm_order.email
@@ -1,4 +1,5 @@
{% load i18n %}
+{% load price from taxed_prices %}
{% load prices_i18n %}
{% load voucher %}
@@ -13,13 +14,14 @@ Hi!
Thank you for your order. Below is the list of ordered products. To see your payment details please visit:
{{ url }}{% endblocktrans %}
{% for line in order %}
-{{ line.quantity }} x {{ line.product_name }}, {{ line.get_total.gross|amount }}
+{{ line.quantity }} x {{ line.product_name }}, {% price line.get_total display_gross=order.display_gross_prices html=False %}
{% endfor %}
{% trans "Order summary" context "Order confirmation e-mail table header" %}:
-{% trans "Subtotal" context "Order confirmation e-mail table header" %}: {{ order.get_subtotal.gross|amount }}
-{% trans "Shipping" context "Order confirmation e-mail table header" %}: {{ order.shipping_price.gross|amount }}
+{% trans "Subtotal" context "Order confirmation e-mail table header" %}: {% price order.get_subtotal display_gross=order.display_gross_prices html=False %}
+{% trans "Shipping" context "Order confirmation e-mail table header" %}: {% price order.shipping_price display_gross=order.display_gross_prices html=False %}
+{% if order.display_gross_prices %}{% trans "Taxes (included)" context "Order confirmation e-mail table header" %}{% else %}{% trans "Taxes" context "Order confirmation e-mail table header" %}{% endif %}: {% price order.total.tax html=False %}
{% if order.discount_amount %}{% trans "Discount:" context "Order confirmation e-mail table header" %} {% discount_as_negative order.discount_amount %}{% endif %}
-{% trans "Total" context "Order confirmation e-mail table header" %}: {{ order.total.gross|amount }}
+{% trans "Total" context "Order confirmation e-mail table header" %}: {% price order.total.gross html=False %}
{% trans "Billing address" context "Order confirmation e-mail billing address" %}
{{ order.billing_address }}
diff --git a/templates/templated_email/source/order/partials/_order_lines.mjml b/templates/templated_email/source/order/partials/_order_lines.mjml
index 0af686f3b4..a1ab4f5ce7 100644
--- a/templates/templated_email/source/order/partials/_order_lines.mjml
+++ b/templates/templated_email/source/order/partials/_order_lines.mjml
@@ -1,6 +1,7 @@
<mj-section css-class="no-display">
<mj-column>
<mj-text>
+ {% load price from taxed_prices %}
{% load prices_i18n %}
{% load voucher %}
</mj-text>
@@ -15,7 +16,7 @@
{% trans "Subtotal" context "E-mail order lines summary table" %}
</td>
<td style="text-align: right;">
- {{ order.get_subtotal.gross|amount:'html' }}
+ {% price order.get_subtotal display_gross=order.display_gross_prices html=False %}
</td>
</tr>
<tr>
@@ -23,7 +24,19 @@
{% trans "Shipping" context "E-mail order lines summary table" %}
</td>
<td style="text-align: right;">
- {{ order.shipping_price.gross|amount:'html' }}
+ {% price order.shipping_price display_gross=order.display_gross_prices html=False %}
+ </td>
+ </tr>
+ <tr>
+ <td colspan="3" style="text-align: right;">
+ {% if order.display_gross_prices %}
+ {% trans "Taxes (included)" context "E-mail order lines summary table" %}
+ {% else %}
+ {% trans "Taxes" context "E-mail order lines summary table" %}
+ {% endif %}
+ </td>
+ <td style="text-align: right;">
+ {% price order.total.tax html=False %}
</td>
</tr>
{% if order.discount_amount %}
@@ -41,7 +54,7 @@
<strong>{% trans "Total" context "E-mail order lines summary table" %}</strong>
</td>
<td style="text-align: right;">
- <strong>{{ order.total.gross|amount:'html' }}</strong>
+ <strong>{% price order.total display_gross=order.display_gross_prices html=False %}</strong>
</td>
</tr>
</tfoot>
@@ -59,9 +72,9 @@
<td>{{ line.product_name }}</td>
<td style="text-align: right;">{{ line.quantity }}</td>
<td style="text-align: right;">
- {{ line.unit_price.gross|amount:'html' }}
+ {% price line.unit_price display_gross=order.display_gross_prices html=False %}
</td>
- <td style="text-align: right;">{{ line.get_total.gross|amount }}</td>
+ <td style="text-align: right;">{% price line.get_total display_gross=order.display_gross_prices html=False %}</td>
</tr>
{% endfor %}
</tbody>
diff --git a/tests/conftest.py b/tests/conftest.py
index f1f604af17..572444d134 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -724,5 +724,5 @@ def taxes(tax_rates):
@pytest.fixture
def vatlayer(db, settings, tax_rates, taxes):
settings.VATLAYER_ACCESS_KEY = 'enablevatlayer'
- VAT.objects.create(country_code=settings.DEFAULT_COUNTRY, data=tax_rates)
+ VAT.objects.create(country_code='PL', data=tax_rates)
return taxes
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
index da127a3347..b603b4861f 100644
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -863,7 +863,7 @@ def test_view_order_customer_remove(admin_client, draft_order):
def test_view_order_shipping_edit(
- admin_client, draft_order, shipping_method, settings, taxes):
+ admin_client, draft_order, shipping_method, settings, vatlayer):
method = shipping_method.price_per_country.create(
price=Money(5, settings.DEFAULT_CURRENCY), country_code='PL')
url = reverse(
@@ -878,7 +878,7 @@ def test_view_order_shipping_edit(
assert get_redirect_location(response) == redirect_url
draft_order.refresh_from_db()
assert draft_order.shipping_method_name == shipping_method.name
- assert draft_order.shipping_price == method.get_total_price(taxes)
+ assert draft_order.shipping_price == method.get_total_price(taxes=vatlayer)
assert draft_order.shipping_method == method
diff --git a/tests/test_graphql.py b/tests/test_graphql.py
index 6e155eb885..d1974dbf47 100644
--- a/tests/test_graphql.py
+++ b/tests/test_graphql.py
@@ -183,7 +183,7 @@ def test_product_query(admin_client, product):
amount
}
}
- grossMargin {
+ margin {
start
stop
}
@@ -205,13 +205,13 @@ def test_product_query(admin_client, product):
gross = product_data['availability']['priceRange']['start']['gross']
assert float(gross['amount']) == float(product.price.amount)
from saleor.product.utils.costs import get_product_costs_data
- purchase_cost, gross_margin = get_product_costs_data(product)
+ purchase_cost, margin = get_product_costs_data(product)
assert purchase_cost.start.amount == product_data[
'purchaseCost']['start']['amount']
assert purchase_cost.stop.amount == product_data[
'purchaseCost']['stop']['amount']
- assert gross_margin[0] == product_data['grossMargin'][0]['start']
- assert gross_margin[1] == product_data['grossMargin'][0]['stop']
+ assert margin[0] == product_data['margin'][0]['start']
+ assert margin[1] == product_data['margin'][0]['stop']
def test_product_with_collections(admin_client, product, collection):