From 7a0e68c103d15d15000bd1dcd4b3ab85e1aa3cf3 Mon Sep 17 00:00:00 2001 From: Wilson Cheung Date: Mon, 6 Aug 2018 12:04:27 +0800 Subject: [PATCH] Update ledger/checkout/utils.py calculate_excl_gst set max digits precision on result to 22 and max decimal places to 12 with quantize --- ledger/checkout/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ledger/checkout/utils.py b/ledger/checkout/utils.py index 2a9cf98c77..3b0dedf496 100644 --- a/ledger/checkout/utils.py +++ b/ledger/checkout/utils.py @@ -1,4 +1,4 @@ -from decimal import Decimal as D, ROUND_HALF_DOWN +from decimal import Decimal as D, getcontext from django.contrib.auth import get_user_model from django.contrib.auth.models import AnonymousUser @@ -247,7 +247,9 @@ def get_last_check(self): def calculate_excl_gst(amount): - result = D(100.0)/ D(100 + settings.LEDGER_GST) * D(amount) + TWELVEPLACES = D(10) ** -12 + getcontext().prec = 22 + result = (D(100.0) / D(100 + settings.LEDGER_GST) * D(amount)).quantize(TWELVEPLACES) return result