Skip to content

Commit

Permalink
fix: use float for tax rate and format it locally
Browse files Browse the repository at this point in the history
  • Loading branch information
henri-hulski committed Mar 25, 2022
1 parent a02141b commit 9251acc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions cartridge/shop/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")


Expand Down
2 changes: 1 addition & 1 deletion cartridge/shop/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9251acc

Please sign in to comment.