From 9251accc8d6923f14d6ecfb2b82d6e2bf7c4e554 Mon Sep 17 00:00:00 2001 From: Henri Hulski Date: Fri, 25 Mar 2022 22:07:07 +0100 Subject: [PATCH] fix: use float for tax rate and format it locally --- cartridge/shop/checkout.py | 6 ++++-- cartridge/shop/defaults.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cartridge/shop/checkout.py b/cartridge/shop/checkout.py index 1ca0f48c..78c2bdbb 100644 --- a/cartridge/shop/checkout.py +++ b/cartridge/shop/checkout.py @@ -2,6 +2,7 @@ Checkout process utilities. """ import decimal +import locale from django.utils.translation import gettext_lazy as _ from mezzanine.accounts import ProfileNotConfigured, get_profile_for_user @@ -52,15 +53,16 @@ def default_tax_handler(request, order_form): """ settings.clear_cache() if settings.SHOP_DEFAULT_TAX_RATE: + locale.setlocale(locale.LC_NUMERIC, str(settings.SHOP_CURRENCY_LOCALE)) tax_rate = settings.SHOP_DEFAULT_TAX_RATE if settings.SHOP_TAX_INCLUDED: tax = request.cart.total_price() - ( request.cart.total_price() / decimal.Decimal(1 + tax_rate / 100) ) - tax_type = _("Incl.") + " " + str(tax_rate) + "% " + _("VAT") + tax_type = _("Incl.") + " " + f"{tax_rate:n}" + "% " + _("VAT") else: tax = request.cart.total_price() * decimal.Decimal(tax_rate / 100) - tax_type = _("VAT") + " (" + str(tax_rate) + "%)" + tax_type = _("VAT") + " (" + f"{tax_rate:n}" + "%)" set_tax(request, tax_type, f"{tax:.2f}") diff --git a/cartridge/shop/defaults.py b/cartridge/shop/defaults.py index c2bc45e1..4bc99772 100644 --- a/cartridge/shop/defaults.py +++ b/cartridge/shop/defaults.py @@ -174,7 +174,7 @@ label=_("Default Tax Rate"), description=_("Default tax rate in % when no custom tax handling is implemented."), editable=True, - default=0, + default=0.0, ) register_setting(