Skip to content

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

Unify displaying orders in dashboard and storefront

Anna Siwik9305dbe0d0c5
diff --git a/saleor/checkout/core.py b/saleor/checkout/core.py
index 175bee4692..7f43e97ae3 100644
--- a/saleor/checkout/core.py
+++ b/saleor/checkout/core.py
@@ -309,8 +309,8 @@ class Checkout:
shipping_method_name = (
smart_text(self.shipping_method) if self.is_shipping_required
else None)
- include_taxes_in_prices = (
- Site.objects.get_current().settings.include_taxes_in_prices)
+ display_gross_prices = (
+ Site.objects.get_current().settings.display_gross_prices)
order_data = {
'language_code': get_language(),
'billing_address': billing_address,
@@ -319,7 +319,7 @@ class Checkout:
'shipping_price': self.shipping_price,
'shipping_method_name': shipping_method_name,
'total': self.get_total(),
- 'include_taxes_in_prices': include_taxes_in_prices}
+ 'display_gross_prices': display_gross_prices}
if self.user.is_authenticated:
order_data['user'] = self.user
diff --git a/saleor/core/templatetags/taxed_prices.py b/saleor/core/templatetags/taxed_prices.py
index ea220e0991..e2b10ff4a5 100644
--- a/saleor/core/templatetags/taxed_prices.py
+++ b/saleor/core/templatetags/taxed_prices.py
@@ -24,21 +24,19 @@ def tax_rate(taxes, rate_name):
return tax['value']
[email protected]_tag('taxed_price.html', takes_context=True)
-def taxed_price(context, base, display_gross=None):
[email protected]_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
- price = base
-
if isinstance(base, TaxedMoneyRange):
if display_gross:
- price = MoneyRange(start=base.start.gross, stop=base.stop.gross)
+ base = MoneyRange(start=base.start.gross, stop=base.stop.gross)
else:
- price = MoneyRange(start=base.start.net, stop=base.stop.net)
+ base = MoneyRange(start=base.start.net, stop=base.stop.net)
if isinstance(base, TaxedMoney):
- price = base.gross if display_gross else base.net
+ base = base.gross if display_gross else base.net
- is_range = isinstance(price, MoneyRange)
- return {'price': price, 'is_range': is_range}
+ is_range = isinstance(base, MoneyRange)
+ return {'price': base, 'is_range': is_range}
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 4641e02cfa..3aa8f5b13e 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -169,7 +169,8 @@ class OrderShippingForm(forms.ModelForm):
method = self.instance.shipping_method
if method:
- method_field.set_initial(method, label=method.ajax_label)
+ method_field.set_initial(
+ method, label=method.get_ajax_label(self.taxes))
if self.instance.shipping_address:
country_code = self.instance.shipping_address.country.code
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index bf12b0cb1e..6d7d2cf643 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -57,11 +57,10 @@ def order_list(request):
@staff_member_required
@permission_required('order.edit_order')
def order_create(request):
- include_taxes_in_prices = (
- Site.objects.get_current().settings.include_taxes_in_prices)
+ display_gross_prices = (
+ Site.objects.get_current().settings.display_gross_prices)
order = Order.objects.create(
- status=OrderStatus.DRAFT,
- include_taxes_in_prices=include_taxes_in_prices)
+ status=OrderStatus.DRAFT, display_gross_prices=display_gross_prices)
msg = pgettext_lazy(
'Dashboard message related to an order',
'Draft order created')
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 026d5aa191..4fed827281 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -191,12 +191,14 @@ def product_details(request, pk):
# management.
no_variants = not product.product_type.has_variants
only_variant = variants.first() if no_variants else None
+ include_taxes_in_prices = request.site.settings.include_taxes_in_prices
ctx = {
'product': product, 'sale_price': sale_price,
'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()}
+ 'gross_margin': gross_margin, 'is_empty': not variants.exists(),
+ 'include_taxes_in_prices': include_taxes_in_prices}
return TemplateResponse(request, 'dashboard/product/detail.html', ctx)
diff --git a/saleor/order/migrations/0046_orderline_taxes.py b/saleor/order/migrations/0046_order_line_taxes.py
similarity index 84%
rename from saleor/order/migrations/0046_orderline_taxes.py
rename to saleor/order/migrations/0046_order_line_taxes.py
index 733f5102ba..e3c663d929 100644
--- a/saleor/order/migrations/0046_orderline_taxes.py
+++ b/saleor/order/migrations/0046_order_line_taxes.py
@@ -1,4 +1,4 @@
-# Generated by Django 2.0.3 on 2018-04-16 07:58
+# Generated by Django 2.0.3 on 2018-04-23 10:18
from django.db import migrations, models
@@ -10,14 +10,14 @@ class Migration(migrations.Migration):
]
operations = [
+ migrations.AddField(
+ model_name='order',
+ name='display_gross_prices',
+ field=models.BooleanField(default=True),
+ ),
migrations.AddField(
model_name='orderline',
name='tax_rate',
field=models.DecimalField(decimal_places=2, default='0.0', max_digits=5),
),
- migrations.AddField(
- model_name='order',
- name='include_taxes_in_prices',
- field=models.BooleanField(default=True),
- ),
]
diff --git a/saleor/order/models.py b/saleor/order/models.py
index bf20606cb3..bb3dc491df 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -87,7 +87,7 @@ class Order(models.Model):
currency=settings.DEFAULT_CURRENCY, max_digits=12,
decimal_places=settings.DEFAULT_DECIMAL_PLACES, default=0)
discount_name = models.CharField(max_length=255, default='', blank=True)
- include_taxes_in_prices = models.BooleanField(default=True)
+ display_gross_prices = models.BooleanField(default=True)
objects = OrderQueryset.as_manager()
diff --git a/templates/cart/_subtotal_table.html b/templates/cart/_subtotal_table.html
index c15251809d..dde62aa396 100644
--- a/templates/cart/_subtotal_table.html
+++ b/templates/cart/_subtotal_table.html
@@ -11,7 +11,7 @@
<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 %}>
{% spaceless %}
- {% taxed_price cart_total %}
+ {% price cart_total %}
<br>
<small>
({{ cart_total.net|amount:'html' }} + {{ cart_total.tax|amount:'html' }} VAT)
@@ -20,7 +20,7 @@
<br>
<small>
&asymp;
- {% taxed_price local_cart_total %}
+ {% price local_cart_total %}
</small>
{% endif %}
{% endspaceless %}
diff --git a/templates/cart/index.html b/templates/cart/index.html
index 6bcd50ca7a..510b04334d 100644
--- a/templates/cart/index.html
+++ b/templates/cart/index.html
@@ -3,7 +3,7 @@
{% load get_thumbnail from product_images %}cart
{% load prices_i18n %}
{% load staticfiles %}
-{% load taxed_price from taxed_prices %}
+{% load price from taxed_prices %}
{% block title %}{% trans "Your cart" context "Cart page title" %} — {{ block.super }}{% endblock %}
@@ -65,7 +65,7 @@
</div>
<div class="cart-item-price col-md-5 col-12" data-product-id="{{ line.variant.pk }}">
<p class="text-right">
- {% taxed_price line.get_total %}
+ {% price line.get_total %}
</p>
<p class="small text-right">
({{ line.get_total.net|amount:'html' }} + {{ line.get_total.tax|amount:'html' }} VAT)
diff --git a/templates/cart_dropdown.html b/templates/cart_dropdown.html
index 8f14a413e7..d6d3d9bafa 100644
--- a/templates/cart_dropdown.html
+++ b/templates/cart_dropdown.html
@@ -3,7 +3,7 @@
{% load placeholder %}
{% load prices_i18n %}
{% load staticfiles %}
-{% load taxed_price from taxed_prices %}
+{% load price from taxed_prices %}
<div class="container">
{% if quantity > 0 %}
@@ -27,7 +27,7 @@
<div class="col-md-2">
<div class="float-right">
<h3>
- {% taxed_price line.line_total %}
+ {% price line.line_total %}
</h3>
</div>
</div>
@@ -44,7 +44,7 @@
<div class="col-md-4">
<h3 class="float-md-right price {% if lines|length <= 2 %}single{% endif %}" data-quantity="{{ quantity }}">
<p>
- {% taxed_price total %}
+ {% price total %}
</p>
</h3>
</div>
diff --git a/templates/checkout/details.html b/templates/checkout/details.html
index 54659cb0e8..bec956449f 100644
--- a/templates/checkout/details.html
+++ b/templates/checkout/details.html
@@ -3,7 +3,7 @@
{% load i18n %}
{% load prices_i18n %}
{% load staticfiles %}
-{% load taxed_price from taxed_prices %}
+{% load price from taxed_prices %}
{% block title %}{% trans "Checkout" context "Checkout page title" %} — {{ block.super }}{% endblock %}
@@ -40,7 +40,7 @@
</div>
<div class="col-4">
<p class="float-right">
- {% taxed_price line_total %}
+ {% price line_total %}
</p>
</div>
<div class="col-12">
@@ -56,7 +56,7 @@
</div>
<div class="col-4">
<p class="float-right">
- {% taxed_price checkout.get_subtotal %}
+ {% price checkout.get_subtotal %}
</p>
</div>
<div class="col-12">
@@ -72,7 +72,7 @@
<div class="col-4">
<p class="float-right">
{% if checkout.shipping_method %}
- {% taxed_price checkout.shipping_price %}
+ {% price checkout.shipping_price %}
{% else %}
&mdash;
{% endif %}
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index be8ef85a9b..a053bffa4f 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -6,7 +6,7 @@
{% load prices_i18n %}
{% load staticfiles %}
{% load status %}
-{% load taxed_price from taxed_prices %}
+{% load price from taxed_prices %}
{% load voucher %}
{% block title %}
@@ -320,7 +320,7 @@
({{ line.unit_price.net|amount:'html' }} + {{ line.unit_price.tax|amount:'html' }} VAT)
</td>
<td class="right-align">
- {% taxed_price line.unit_price order.include_taxes_in_prices %}
+ {% price line.unit_price order.display_gross_prices %}
</td>
<td class="right-align">
{% if perms.order.edit_order and order.is_draft %}
@@ -348,18 +348,14 @@
({{ line.get_total.net|amount:'html' }} + {{ line.get_total.tax|amount:'html' }} VAT)
</td>
<td class="right-align">
- {% taxed_price line.get_total order.include_taxes_in_prices %}
+ {% price line.get_total display_gross=order.display_gross_prices %}
</td>
</tr>
{% endfor %}
<tr class="last-no-border">
<td class="right-align" colspan="5">
<p>
- {% if order.include_taxes_in_prices %}
- {% trans "Subtotal" context "Order subtotal" %}
- {% else %}
- {% trans "Subtotal net" context "Order subtotal" %}
- {% endif %}
+ {% trans "Subtotal" context "Order subtotal" %}
</p>
<p>debug</p>
<p>
@@ -386,7 +382,7 @@
</p>
<p>debug</p>
<p>
- {% if order.include_taxes_in_prices %}
+ {% if order.display_gross_prices %}
{% trans "Taxes (included)" context "Order total taxes" %}
{% else %}
{% trans "Taxes" context "Order total taxes" %}
@@ -435,13 +431,13 @@
</td>
<td class="right-align">
<p>
- {% taxed_price order.get_subtotal order.include_taxes_in_prices %}
+ {% price order.get_subtotal display_gross=order.display_gross_prices %}
</p>
<p>
({{ order.get_subtotal.net|amount:'html' }} + {{ order.get_subtotal.tax|amount:'html' }} VAT)
</p>
<p>
- {% taxed_price order.shipping_price order.include_taxes_in_prices %}
+ {% price order.shipping_price display_gross=order.display_gross_prices %}
</p>
<p>
({{ order.shipping_price.net|amount:'html' }} + {{ order.shipping_price.tax|amount:'html' }} VAT)
diff --git a/templates/dashboard/order/modal/cancel_line.html b/templates/dashboard/order/modal/cancel_line.html
index 3347594304..f43115cf3a 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 taxed_price from taxed_prices %}
+{% load price from taxed_prices %}
{% block action_url %}
{% url 'dashboard:orderline-cancel' order_pk=order.pk line_pk=item.pk %}
@@ -48,13 +48,13 @@
{{ item.product_sku }}
</td>
<td class="right-align">
- {% taxed_price item.unit_price order.include_taxes_in_prices %}
+ {% price item.unit_price display_gross=order.display_gross_prices %}
</td>
<td class="right-align">
{{ item.quantity }}
</td>
<td class="right-align">
- {% taxed_price item.get_total order.include_taxes_in_prices %}
+ {% price item.get_total display_gross=order.display_gross_prices %}
</td>
</tr>
</tbody>
diff --git a/templates/dashboard/product/detail.html b/templates/dashboard/product/detail.html
index f4374cbf61..eeecb60a86 100644
--- a/templates/dashboard/product/detail.html
+++ b/templates/dashboard/product/detail.html
@@ -4,7 +4,7 @@
{% load prices_i18n %}
{% load staticfiles %}
{% load status %}
-{% load taxed_price from taxed_prices %}
+{% load price from taxed_prices %}
{% load utils %}
{% block title %}{{ product }} - {{ block.super }}{% endblock %}
@@ -101,7 +101,7 @@
<th>{% trans "Name" %}</th>
<th>{% trans "Status" %}</th>
<th class="right-align">
- {% if request.site.settings.include_taxes_in_prices %}
+ {% if include_taxes_in_prices %}
{% trans "Price (gross)" %}
{% else %}
{% trans "Price (net)" %}
@@ -170,62 +170,60 @@
</div>
</div>
<div class="data-table-container">
- {% with request.site.settings.include_taxes_in_prices as display_gross_prices %}
- <table class="data-table bordered highlight">
- <tbody>
+ <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 display_gross_prices %}
- {% trans "Sale price (gross)" context "Product field" %}
+ {% if include_taxes_in_prices %}
+ {% trans "Discounted price (gross)" context "Product field" %}
{% else %}
- {% trans "Sale price (net)" context "Product field" %}
+ {% trans "Discounted price (net)" context "Product field" %}
{% endif %}
</td>
<td class="right-align">
- {% taxed_price sale_price display_gross_prices %}
+ {% price discounted_price display_gross=include_taxes_in_prices %}
</td>
</tr>
- {% 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">
- {% taxed_price discounted_price display_gross_prices %}
- </td>
- </tr>
- {% endif %}
- <tr>
- <td>
- {% trans "Purchase cost" context "Product field" %}
- </td>
- <td class="right-align">
- {% taxed_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 %}
+ {% 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 %}
- </td>
- </tr>
- </tbody>
- </table>
- {% endwith %}
+ {% else %}
+ -
+ {% endif %}
+ </td>
+ </tr>
+ </tbody>
+ </table>
</div>
</div>
</div>
diff --git a/templates/dashboard/shipping/list.html b/templates/dashboard/shipping/list.html
index 77797df528..0dc3ef71e1 100644
--- a/templates/dashboard/shipping/list.html
+++ b/templates/dashboard/shipping/list.html
@@ -62,7 +62,7 @@
{% if not method.price_range %}
-
{% else %}
- {% taxed_price method.price_range request.site.settings.include_taxes_in_prices %}
+ {% price method.price_range %}
{% endif %}
</td>
<td>
diff --git a/templates/order/_ordered_items_table.html b/templates/order/_ordered_items_table.html
index 92fcf0516e..be5745faa4 100644
--- a/templates/order/_ordered_items_table.html
+++ b/templates/order/_ordered_items_table.html
@@ -4,7 +4,7 @@
{% load i18n_address_tags %}
{% load placeholder %}
{% load product_first_image from product_images %}
-{% load taxed_price from taxed_prices %}
+{% load price from taxed_prices %}
{% if order.user == user %}
<div class="order-details__addresses">
@@ -65,7 +65,7 @@
</div>
<div class="col-md-6 col-12">
<p class="float-right">
- {% taxed_price line.get_total %}
+ {% price line.get_total display_gross=order.display_gross_prices %}
</p>
<p class="float-right">
({{ line.get_total.net|amount:'html' }} + {{ line.get_total.tax|amount:'html' }} VAT)
@@ -81,16 +81,12 @@
<div class="row">
<div class="col-8 order-details__table-footer">
<p>
- {% if request.site.settings.display_gross_prices %}
- {% trans "Subtotal" context "Order details subtotal row text" %}
- {% else %}
- {% trans "Subtotal net" context "Order details subtotal row text" %}
- {% endif %}
+ {% trans "Subtotal" context "Order details subtotal row text" %}
</p>
</div>
<div class="col-4">
<p class="float-right">
- {% taxed_price order.get_subtotal %}
+ {% price order.get_subtotal display_gross=order.display_gross_prices %}
</p>
<br>
<p class="float-right">
@@ -110,7 +106,7 @@
</div>
<div class="col-4">
<p class="float-right">
- {% taxed_price order.shipping_price %}
+ {% price order.shipping_price display_gross=order.display_gross_prices %}
</p>
<br>
<p class="float-right">
@@ -140,7 +136,7 @@
<div class="row">
<div class="col-8 order-details__table-footer">
<p>
- {% if request.site.settings.display_gross_prices %}
+ {% if order.display_gross_prices %}
{% trans "Taxes (included)" context "Order details taxes text" %}
{% else %}
{% trans "Taxes" context "Order details taxes text" %}
diff --git a/templates/taxed_price.html b/templates/price.html
similarity index 100%
rename from templates/taxed_price.html
rename to templates/price.html
diff --git a/templates/product/details.html b/templates/product/details.html
index 676da2eee7..7966dfc103 100644
--- a/templates/product/details.html
+++ b/templates/product/details.html
@@ -131,14 +131,14 @@
<span>{% price_range availability.price_range %}</span>
{% if availability.discount %}
<small class="product__info__price__undiscounted">
- {% taxed_price availability.price_range_undiscounted %}
+ {% price availability.price_range_undiscounted %}
</small>
{% endif %}
{% if availability.price_range_local_currency %}
<br>
<small class="text-info">
&asymp;
- {% taxed_price availability.price_range_local_currency %}
+ {% price availability.price_range_local_currency %}
</small>
{% endif %}
<small>
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
index c95b5d0382..da127a3347 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):
+ admin_client, draft_order, shipping_method, settings, taxes):
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()
+ assert draft_order.shipping_price == method.get_total_price(taxes)
assert draft_order.shipping_method == method
diff --git a/tests/test_order.py b/tests/test_order.py
index f275b66690..c5d5315b56 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -336,7 +336,8 @@ def test_order_queryset_to_ship():
def test_ajax_order_shipping_methods_list(
admin_client, order, shipping_method):
method = shipping_method.price_per_country.get()
- shipping_methods_list = [{'id': method.pk, 'text': method.ajax_label}]
+ shipping_methods_list = [
+ {'id': method.pk, 'text': method.get_ajax_label()}]
url = reverse(
'dashboard:ajax-order-shipping-methods', kwargs={'order_pk': order.pk})
@@ -352,7 +353,8 @@ def test_ajax_order_shipping_methods_list_different_country(
order.shipping_address = order.billing_address.get_copy()
order.save()
method = shipping_method.price_per_country.get()
- shipping_methods_list = [{'id': method.pk, 'text': method.ajax_label}]
+ shipping_methods_list = [
+ {'id': method.pk, 'text': method.get_ajax_label()}]
shipping_method.price_per_country.create(price=15, country_code='DE')
url = reverse(
'dashboard:ajax-order-shipping-methods', kwargs={'order_pk': order.pk})