Skip to content

Commit

Permalink
feat: add SHOP_TAX_INCLUDED setting when prices already include tax
Browse files Browse the repository at this point in the history
  • Loading branch information
henri-hulski committed Mar 23, 2022
1 parent 5488bc4 commit ab54323
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions cartridge/shop/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,11 @@
editable=False,
default=True,
)

register_setting(
name="SHOP_TAX_INCLUDED",
label=_("Tax included"),
description="The product prices are already including tax (boolean).",
editable=False,
default=False,
)
2 changes: 1 addition & 1 deletion cartridge/shop/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def setup(self, request):
self.total += self.shipping_total
if self.discount_total is not None:
self.total -= Decimal(self.discount_total)
if self.tax_total is not None:
if self.tax_total is not None and not settings.SHOP_TAX_INCLUDED:
self.total += Decimal(self.tax_total)
self.save() # We need an ID before we can add related items.
for item in request.cart:
Expand Down
6 changes: 5 additions & 1 deletion cartridge/shop/templatetags/shop_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from decimal import Decimal

from django import template
from mezzanine.conf import settings

from cartridge.shop.utils import set_locale

Expand Down Expand Up @@ -60,7 +61,10 @@ def _order_totals(context):
template_vars["order_total"] += Decimal(str(template_vars["shipping_total"]))
if template_vars.get("discount_total", None) is not None:
template_vars["order_total"] -= Decimal(str(template_vars["discount_total"]))
if template_vars.get("tax_total", None) is not None:
if (
template_vars.get("tax_total", None) is not None
and not settings.SHOP_TAX_INCLUDED
):
template_vars["order_total"] += Decimal(str(template_vars["tax_total"]))
return template_vars

Expand Down

0 comments on commit ab54323

Please sign in to comment.