Skip to content

Commit

Permalink
using __futures__ to have common division across py versions (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninsy authored and tarnas14 committed Mar 16, 2018
1 parent c65ace0 commit 70f7b2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def test_shouldCalculateAmountPriceDiscount():
}
discount = utils.calculate_discount(base_price, voucher, unit_price)
price = utils.calculate_price(base_price, voucher, unit_price)
assert discount == 124
assert price == 960.85
assert discount == 124.36
assert price == 960.49

def test_shouldCalculateAmountDiscountWhenGiftIsNone():
voucher = {
Expand All @@ -44,5 +44,5 @@ def test_shouldCalculateAmountDiscountWhenGiftIsNone():
}
discount = utils.calculate_discount(base_price, voucher, unit_price)
price = utils.calculate_price(base_price, voucher, unit_price)
assert discount == 124
assert price == 960.85
assert discount == 124.36
assert price == 960.49
4 changes: 3 additions & 1 deletion voucherify/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import division

def round_money(value):
if value is None or value < 0:
raise Exception('Invalid value, amount should be a number and higher than zero.')
Expand All @@ -24,7 +26,7 @@ def calculate_price(base_price, voucher, unit_price):

if getattr(voucher, 'gift', None) is not None:
discount = min(voucher['gift']['balance'] / e, base_price)
return round_money(base_price - discount)
return round_money(base_price - discount)

if 'discount' not in voucher:
raise Exception('Unsupported voucher type.')
Expand Down

0 comments on commit 70f7b2a

Please sign in to comment.