Bug with balance result?

26 views
Skip to first unread message

Olivier Lauret

unread,
Aug 2, 2012, 3:28:51 AM8/2/12
to satchm...@googlegroups.com
Hi all,

I have the following problem:

order.sub_total = £4.16
TAX = 0.83
order.shopping_cost = £2.75
order.total = £7.74
But:
order.balance = £7.75

The problem comes from the utils.numbers.trunc_decimal function which rounds up the order.total of 7.742.

Is this a normal behaviour for the balance or am I missing one setting somewhere?

Regards,
Olivier

Darren Hollenbeck

unread,
Oct 5, 2012, 1:18:40 PM10/5/12
to satchm...@googlegroups.com, olivier...@googlemail.com
I'm seeing the same thing: a one-cent difference in order.total and order.balance... which, on the confirmation page in checkout process, ends up saying their card will be charged for $0.01 more than the order total due to this rounding difference.

Anyone have knowledge if this is intended behavior?

Darren Hollenbeck

unread,
Oct 5, 2012, 1:23:45 PM10/5/12
to satchm...@googlegroups.com, olivier...@googlemail.com
I found mention of trunc_decimal in another posting, did some looking...

In the Order model, force_recalculate_total() sets total as Decimal based on the various parts (sub_total, shipping, tax) but does not truncate it.

_balance() does trunc_decimal()... that seems to be the difference.

Bug?

Olivier Lauret

unread,
Oct 5, 2012, 2:08:25 PM10/5/12
to Darren Hollenbeck, satchm...@googlegroups.com

Hi Darren,

The way I have worked around this issue on my website (www.equalitea.co.uk) is as follow:

The problem with taxes is that it has to round up the value (this is by law in the UK and I think it should be the same in many countries) and this exactly what the payment module is doing. This is however not the case of the shop when you set that the price already contains the vat (this I'd the case in Europe). The way I got around it is to make sure that you set the price without vat with 4 digits (i don't know how many digits are enough but this is what I'm doing) for the cents so that with the taxes it slightly below the exact value I want. For instance (not sure I was clear in what I said!), if I want a price to show as £4.99, you need to subtract the equivalent of the vat (20% in the UK), and round it down at 4 digit for the cents. In my case, the number will be 4.1583 . Therefore, I know that with when the vat is added, it will be a prove very close to 4.99, without going above it. (hope this is clearer now!)

I don't know if this I'd the way to do, that's why I didn't reply to my own message. So if someone can clarify, this would be great. Otherwise, I hope my answer will help.

Regards,
Olivier

On Oct 5, 2012 6:23 PM, "Darren Hollenbeck" <dar...@softplc.com> wrote:

Darren Hollenbeck

unread,
Jun 11, 2013, 11:13:08 AM6/11/13
to satchm...@googlegroups.com, Darren Hollenbeck, olivier...@googlemail.com
Hi Oliver,

I know this is a late reply, sorry.

I made a 1-line modification in satchmo/apps/satchmo_store/shop/models.py to fix this issue for me. In the function force_recalculate_total (under the Order model) find the line:
self.total = Decimal(item_sub_total + self.shipping_sub_total + self.tax)
I then added below that the following:
self.total = trunc_decimal(self.total-self.balance_paid, 2)

This mimics the behavior in the _balance function (which calls force_recalculate_total anyway). However _balance is not always used so this 'fixes' the discrepancy when force_recalculate_total is used directly.

- Darren
Reply all
Reply to author
Forward
0 new messages