Fixed #119 -- Explicitly set decimal rounding mode

This commit is contained in:
Raphael Michel
2016-02-11 17:27:11 +01:00
parent 417539d101
commit 0741c00133
4 changed files with 13 additions and 4 deletions

View File

@@ -3,6 +3,8 @@ import tempfile
import time
from decimal import Decimal
from pretix.base.decimal import round_decimal
def hbci_transactions(event, conf):
try:
@@ -92,7 +94,7 @@ def hbci_transactions(event, conf):
num = int(parts[0])
denom = int(parts[1])
value = Decimal(num) / Decimal(denom)
value = str(value.quantize(Decimal('.01')))
value = str(round_decimal(value))
data.append({
'payer': "\n".join(payer),
'reference': trans.find('purpose').find('value').text,

View File

@@ -1,8 +1,9 @@
import io
from decimal import Decimal
import mt940
from pretix.base.decimal import round_decimal
def parse(file):
data = file.read()
@@ -20,7 +21,7 @@ def parse(file):
'reference': "\n".join([
t.data.get(f) for f in ('transaction_details', 'customer_reference', 'bank_reference',
'extra_details') if t.data.get(f, '')]),
'amount': str(t.data['amount'].amount.quantize(Decimal('.01'))),
'amount': str(round_decimal(t.data['amount'].amount)),
'date': t.data['date'].isoformat()
})
return result