summaryrefslogtreecommitdiff
path: root/postgresqleu/confreg/util.py
diff options
context:
space:
mode:
authorMagnus Hagander2019-01-04 14:21:00 +0000
committerMagnus Hagander2019-01-04 14:21:00 +0000
commit40493ac75d12dba360658f8bd6ee03b66a70b81d (patch)
treec6c6010c71a4c109d5ef0548392ba58d026491c0 /postgresqleu/confreg/util.py
parent6d44349af29bcd83e477a48e2a555c1314bce7eb (diff)
Use proper floor division operator
py3 changes the / operator from current integer division (floor division) to instead be true division (float division). The // operator exists in both py3 and py2 and always performs floor division. Most of our important calculations already use Decimal with explicit number of decimal points which is safe against this. But for some cases like calculating pixels in pdfs and reports make sure that we explicitly use the // so we don't risk a change in behaviour when we eventually switch to py3.
Diffstat (limited to 'postgresqleu/confreg/util.py')
-rw-r--r--postgresqleu/confreg/util.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/postgresqleu/confreg/util.py b/postgresqleu/confreg/util.py
index 656da520..d3a79daa 100644
--- a/postgresqleu/confreg/util.py
+++ b/postgresqleu/confreg/util.py
@@ -3,6 +3,7 @@ from django.shortcuts import get_object_or_404
from django.conf import settings
from django.core.exceptions import PermissionDenied
+from decimal import Decimal
from datetime import datetime, date, timedelta
import urllib
from io import BytesIO
@@ -88,9 +89,10 @@ def invoicerows_for_registration(reg, update_used_vouchers):
else:
# Percentage discount. Can be either off the total or just the reg
if d.regonly:
+ # regtype.cost is Decimal
discount = reg.regtype.cost * d.discountpercentage / 100
else:
- discount = current_total * d.discountpercentage / 100
+ discount = Decimal(current_total) * d.discountpercentage / 100
if discount > 0:
r.append([' Discount code %s' % d.code, 1, -discount, reg.conference.vat_registrations])
except DiscountCode.DoesNotExist: