mirror of
https://github.com/pretix/pretix.git
synced 2026-05-10 16:04:02 +00:00
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 django.utils.translation import ugettext_lazy as _
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
|
from pretix.base.decimal import round_decimal
|
||||||
from pretix.base.models import CartPosition, Event, Order, Quota
|
from pretix.base.models import CartPosition, Event, Order, Quota
|
||||||
from pretix.base.settings import SettingsSandbox
|
from pretix.base.settings import SettingsSandbox
|
||||||
from pretix.base.signals import register_payment_providers
|
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_abs = self.settings.get('_fee_abs', as_type=Decimal, default=0)
|
||||||
fee_percent = self.settings.get('_fee_percent', 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
|
@property
|
||||||
def verbose_name(self) -> str:
|
def verbose_name(self) -> str:
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import tempfile
|
|||||||
import time
|
import time
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
from pretix.base.decimal import round_decimal
|
||||||
|
|
||||||
|
|
||||||
def hbci_transactions(event, conf):
|
def hbci_transactions(event, conf):
|
||||||
try:
|
try:
|
||||||
@@ -92,7 +94,7 @@ def hbci_transactions(event, conf):
|
|||||||
num = int(parts[0])
|
num = int(parts[0])
|
||||||
denom = int(parts[1])
|
denom = int(parts[1])
|
||||||
value = Decimal(num) / Decimal(denom)
|
value = Decimal(num) / Decimal(denom)
|
||||||
value = str(value.quantize(Decimal('.01')))
|
value = str(round_decimal(value))
|
||||||
data.append({
|
data.append({
|
||||||
'payer': "\n".join(payer),
|
'payer': "\n".join(payer),
|
||||||
'reference': trans.find('purpose').find('value').text,
|
'reference': trans.find('purpose').find('value').text,
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import io
|
import io
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
import mt940
|
import mt940
|
||||||
|
|
||||||
|
from pretix.base.decimal import round_decimal
|
||||||
|
|
||||||
|
|
||||||
def parse(file):
|
def parse(file):
|
||||||
data = file.read()
|
data = file.read()
|
||||||
@@ -20,7 +21,7 @@ def parse(file):
|
|||||||
'reference': "\n".join([
|
'reference': "\n".join([
|
||||||
t.data.get(f) for f in ('transaction_details', 'customer_reference', 'bank_reference',
|
t.data.get(f) for f in ('transaction_details', 'customer_reference', 'bank_reference',
|
||||||
'extra_details') if t.data.get(f, '')]),
|
'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()
|
'date': t.data['date'].isoformat()
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user