Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix displaying prices
Anna Siwikea4af904a6cb
diff --git a/saleor/core/utils/taxes.py b/saleor/core/utils/taxes.pyindex 9e36ebef7a..258b9c5075 100644--- a/saleor/core/utils/taxes.py+++ b/saleor/core/utils/taxes.py@@ -7,9 +7,8 @@ from prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRangeDEFAULT_TAX_RATE_NAME = 'standard'-ZERO_TAXED_MONEY = TaxedMoney(- net=Money(0, settings.DEFAULT_CURRENCY),- gross=Money(0, settings.DEFAULT_CURRENCY))+ZERO_MONEY = Money(0, settings.DEFAULT_CURRENCY)+ZERO_TAXED_MONEY = TaxedMoney(net=ZERO_MONEY, gross=ZERO_MONEY)def apply_tax_to_price(taxes, rate_name, base):diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.pyindex e56a0a54ef..349c73abef 100644--- a/saleor/dashboard/discount/forms.py+++ b/saleor/dashboard/discount/forms.py@@ -5,9 +5,9 @@ from django.conf import settingsfrom django.urls import reverse_lazyfrom django.utils.translation import pgettext_lazyfrom django_prices.forms import MoneyField-from prices import Moneyfrom ...core.i18n import COUNTRY_CODE_CHOICES+from ...core.utils.taxes import ZERO_MONEYfrom ...discount import DiscountValueType, VoucherApplyToProductfrom ...discount.models import Sale, Voucherfrom ...product.models import Product@@ -116,8 +116,8 @@ def country_choices():class ShippingVoucherForm(forms.ModelForm):limit = MoneyField(- min_value=Money(0, settings.DEFAULT_CURRENCY),- required=False, currency=settings.DEFAULT_CURRENCY)+ min_value=ZERO_MONEY, required=False,+ currency=settings.DEFAULT_CURRENCY)apply_to = forms.ChoiceField(choices=country_choices,required=False)@@ -142,8 +142,8 @@ class ShippingVoucherForm(forms.ModelForm):class ValueVoucherForm(forms.ModelForm):limit = MoneyField(- min_value=Money(0, settings.DEFAULT_CURRENCY),- required=False, currency=settings.DEFAULT_CURRENCY)+ min_value=ZERO_MONEY, required=False,+ currency=settings.DEFAULT_CURRENCY)class Meta:model = Voucherdiff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.pyindex ab7c8c5d6a..faf910c032 100644--- a/saleor/dashboard/order/utils.py+++ b/saleor/dashboard/order/utils.py@@ -1,8 +1,8 @@from django.conf import settingsfrom django.contrib.sites.shortcuts import get_current_sitefrom django.template.loader import get_template-from prices import Money+from ...core.utils.taxes import ZERO_MONEYfrom ...discount import VoucherTypefrom ...discount.models import NotApplicablefrom ...discount.utils import (@@ -106,7 +106,7 @@ def _get_value_voucher_discount_for_order(order):discount_amount = get_value_voucher_discount(order.voucher, order.get_subtotal())except NotApplicable:- discount_amount = Money(0, settings.DEFAULT_CURRENCY)+ discount_amount = ZERO_MONEYreturn discount_amount@@ -116,7 +116,7 @@ def _get_shipping_voucher_discount_for_order(order):discount_amount = get_shipping_voucher_discount(order.voucher, order.get_subtotal(), order.shipping_price)except NotApplicable:- discount_amount = Money(0, settings.DEFAULT_CURRENCY)+ discount_amount = ZERO_MONEYreturn discount_amount@@ -131,7 +131,7 @@ def _get_product_or_category_voucher_discount_for_order(order):variant_price for _, variant_price inget_category_variants_and_prices(order, order.voucher.category)]if not prices:- return Money(0, settings.DEFAULT_CURRENCY)+ return ZERO_MONEYreturn get_product_or_category_voucher_discount(order.voucher, prices)diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex 513d2fb14d..25e8618160 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -16,7 +16,8 @@ from payments import PaymentStatusfrom ...core.exceptions import InsufficientStockfrom ...core.utils import get_paginator_items-from ...core.utils.taxes import ZERO_TAXED_MONEY, get_taxes_for_address+from ...core.utils.taxes import (+ ZERO_MONEY, ZERO_TAXED_MONEY, get_taxes_for_address)from ...order import CustomPaymentChoices, OrderStatusfrom ...order.emails import (send_fulfillment_confirmation, send_fulfillment_update,@@ -121,8 +122,9 @@ def order_details(request, order_pk):order = get_object_or_404(qs, pk=order_pk)all_payments = order.payments.exclude(status=PaymentStatus.INPUT)payment = order.payments.last()- captured = preauthorized = ZERO_TAXED_MONEY- balance = captured - order.total+ preauthorized = ZERO_TAXED_MONEY+ captured = ZERO_MONEY+ balance = captured - order.total.grossif payment:can_capture = (payment.status == PaymentStatus.PREAUTH and@@ -134,7 +136,7 @@ def order_details(request, order_pk):preauthorized = payment.get_total_price()if payment.status == PaymentStatus.CONFIRMED:captured = payment.get_captured_price()- balance = captured - order.total+ balance = captured - order.total.grosselse:can_capture = can_release = can_refund = Falsecan_mark_as_paid = not order.payments.exists()diff --git a/saleor/discount/utils.py b/saleor/discount/utils.pyindex 370ec8bba1..4be76abdca 100644--- a/saleor/discount/utils.py+++ b/saleor/discount/utils.py@@ -1,10 +1,8 @@-from django.conf import settingsfrom django.db.models import Ffrom django.utils.translation import pgettext-from prices import Moneyfrom . import VoucherApplyToProduct-from ..core.utils.taxes import ZERO_TAXED_MONEY+from ..core.utils.taxes import ZERO_MONEY, ZERO_TAXED_MONEYfrom .models import NotApplicable@@ -77,8 +75,7 @@ def get_product_or_category_voucher_discount(voucher, prices):if voucher.apply_to == VoucherApplyToProduct.ALL_PRODUCTS:discounts = (voucher.get_discount_amount_for(price) for price in prices)- total_amount = sum(- discounts, Money(0, settings.DEFAULT_CURRENCY))+ total_amount = sum(discounts, ZERO_MONEY)return total_amountproduct_total = sum(prices, ZERO_TAXED_MONEY)return voucher.get_discount_amount_for(product_total)diff --git a/saleor/order/models.py b/saleor/order/models.pyindex d195e701f8..ef7b575f62 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -110,9 +110,7 @@ class Order(models.Model):[payment.get_total_price() for payment inself.payments.filter(status=PaymentStatus.CONFIRMED)],- TaxedMoney(- net=Money(0, settings.DEFAULT_CURRENCY),- gross=Money(0, settings.DEFAULT_CURRENCY)))+ ZERO_TAXED_MONEY)return total_paid.gross >= self.total.grossdef get_user_current_email(self):diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex d5462904ff..e48971b975 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -1,13 +1,12 @@from functools import wraps-from django.conf import settingsfrom django.db.models import Ffrom django.shortcuts import get_object_or_404, redirect-from prices import Moneyfrom ..account.utils import store_user_addressfrom ..core.exceptions import InsufficientStock-from ..core.utils.taxes import get_tax_rate_by_name, get_taxes_for_address+from ..core.utils.taxes import (+ ZERO_MONEY, get_tax_rate_by_name, get_taxes_for_address)from ..dashboard.order.utils import get_voucher_discount_for_orderfrom ..order import FulfillmentStatus, OrderStatusfrom ..order.models import OrderLine@@ -44,8 +43,7 @@ def update_voucher_discount(func):if kwargs.pop('update_voucher_discount', True):order = args[0]order.discount_amount = (- get_voucher_discount_for_order(order) or- Money(0, settings.DEFAULT_CURRENCY))+ get_voucher_discount_for_order(order) or ZERO_MONEY)return func(*args, **kwargs)return decoratordiff --git a/saleor/product/utils/costs.py b/saleor/product/utils/costs.pyindex 695d1dfce9..6d758ad02e 100644--- a/saleor/product/utils/costs.py+++ b/saleor/product/utils/costs.py@@ -1,12 +1,10 @@-from django.conf import settings-from prices import Money, MoneyRange+from prices import MoneyRange-from ...core.utils.taxes import ZERO_TAXED_MONEY+from ...core.utils.taxes import ZERO_MONEYdef get_product_costs_data(product):- purchase_costs_range = MoneyRange(- start=ZERO_TAXED_MONEY, stop=ZERO_TAXED_MONEY)+ purchase_costs_range = MoneyRange(start=ZERO_MONEY, stop=ZERO_MONEY)margin = (0, 0)if not product.variants.exists():@@ -52,7 +50,7 @@ def get_variant_costs_data(variant):def get_cost_price(variant):if not variant.cost_price:- return Money(0, settings.DEFAULT_CURRENCY)+ return ZERO_MONEYreturn variant.cost_pricediff --git a/saleor/static/dashboard/js/components/load-action.js b/saleor/static/dashboard/js/components/load-action.jsindex f09f8b7528..877d3e9ace 100644--- a/saleor/static/dashboard/js/components/load-action.js+++ b/saleor/static/dashboard/js/components/load-action.js@@ -3,8 +3,8 @@ function disableSubsequentClicks (e) {}function initLoadAction (e) {- $('body').css('cursor', 'progress')- $(e.target).on('click', disableSubsequentClicks)+ $('body').css('cursor', 'progress');+ $(e.target).on('click', disableSubsequentClicks);}// -----diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.htmlindex d280b69d86..5726cb46c0 100644--- a/templates/dashboard/order/detail.html+++ b/templates/dashboard/order/detail.html@@ -129,7 +129,7 @@</td><td class="right-align"><strong>- {% price balance.gross %}+ {% price balance %}</strong></td></tr>@@ -152,7 +152,7 @@{% trans "Captured amount" context "Order summary card header" %}</td><td class="right-align">- {% price captured.gross %}+ {% price captured %}</td></tr></tbody>diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.pyindex 2d2e1d4db2..ce99a873d6 100644--- a/tests/dashboard/test_order.py+++ b/tests/dashboard/test_order.py@@ -7,7 +7,7 @@ from payments import PaymentStatusfrom prices import Moneyfrom tests.utils import get_form_errors, get_redirect_location-from saleor.core.utils.taxes import ZERO_TAXED_MONEY+from saleor.core.utils.taxes import ZERO_MONEY, ZERO_TAXED_MONEYfrom saleor.dashboard.order.forms import ChangeQuantityForm, OrderNoteFormfrom saleor.dashboard.order.utils import (fulfill_order_line, remove_customer_from_order, save_address_in_order,@@ -1070,7 +1070,7 @@ def test_view_order_voucher_remove(admin_client, draft_order, voucher):assert get_redirect_location(response) == redirect_urldraft_order.refresh_from_db()- assert draft_order.discount_amount == Money(0, settings.DEFAULT_CURRENCY)+ assert draft_order.discount_amount == ZERO_MONEYassert draft_order.total == total_before + discount_amount