Question

I have a calculation that calculates the tax when a user checks out using Cartridge as my shop framework.

tax = tax * Decimal(str(settings.SHOP_DEFAULT_TAX_RATE))

The calculation works properly.I then pass tax to set_tax(request, _("GST+PST"), tax)

When I do that, I get an error Decimal('12.0') is not JSON serializable.

When I convert it to a float (set_tax(request, _("GST+PST"), float(tax)) it works; but when I go through the checkout I get this error:

unsupported operand type(s) for +=: 'Decimal' and 'float'

In my settings:

  • SHOP_DEFAULT_TAX_RATE = 0.12

I've seen solutions where I need to use a custom JSONEncoder but the error occurs inside Django itself.

Thanks.

Was it helpful?

Solution

This was fixed a couple weeks ago but has not yet been released:

https://github.com/stephenmcd/cartridge/commit/628bd203f39a62d9de2613de7057e6742657111f

Fortunately you can add the development version as a dependency right now.

BTW decimal is the correct type to be using.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top