forked from CGM_Public/pretix_original
Fixed #119 -- Explicitly set decimal rounding mode
This commit is contained in:
5
src/pretix/base/decimal.py
Normal file
5
src/pretix/base/decimal.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from decimal import ROUND_HALF_UP, Decimal
|
||||
|
||||
|
||||
def round_decimal(dec):
|
||||
return Decimal(dec).quantize(Decimal('0.01'), ROUND_HALF_UP)
|
||||
@@ -11,6 +11,7 @@ from django.template.loader import get_template
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from typing import Any, Dict
|
||||
|
||||
from pretix.base.decimal import round_decimal
|
||||
from pretix.base.models import CartPosition, Event, Order, Quota
|
||||
from pretix.base.settings import SettingsSandbox
|
||||
from pretix.base.signals import register_payment_providers
|
||||
@@ -47,7 +48,7 @@ class BasePaymentProvider:
|
||||
"""
|
||||
fee_abs = self.settings.get('_fee_abs', as_type=Decimal, default=0)
|
||||
fee_percent = self.settings.get('_fee_percent', as_type=Decimal, default=0)
|
||||
return (price * fee_percent / 100).quantize(Decimal('.01')) + fee_abs
|
||||
return round_decimal(price * fee_percent / 100) + fee_abs
|
||||
|
||||
@property
|
||||
def verbose_name(self) -> str:
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user