Add a maximum budget to vouchers (#1526)

* Data model changes

* Fix test failures

* Adjustments

* Some tests and API support

* Check when extending orders

* Make things more deterministic, fix style

* Do not apply negative discounts

* Update price_before_voucher on item/subevent changes

* Add tests for price_before_voucher in combination with free price

* Fix InvoiceAddress.DoesNotExist
This commit is contained in:
Raphael Michel
2020-01-03 16:15:17 +01:00
committed by GitHub
parent b738e3bd9d
commit 8e2821b398
20 changed files with 649 additions and 23 deletions

View File

@@ -795,6 +795,31 @@ class VoucherTestCase(BaseQuotaTestCase):
v = Voucher.objects.create(event=self.event, price_mode='percent', value=Decimal('23.00'))
assert v.calculate_price(Decimal('100.00')) == Decimal('77.00')
@classscope(attr='o')
def test_calculate_price_max_discount(self):
v = Voucher.objects.create(event=self.event, price_mode='subtract', value=Decimal('10.00'))
assert v.calculate_price(Decimal('23.42'), max_discount=Decimal('5.00')) == Decimal('18.42')
@classscope(attr='o')
def test_calculate_budget_used(self):
v = Voucher.objects.create(event=self.event, price_mode='sset', value=Decimal('20.00'))
order = Order.objects.create(
status=Order.STATUS_PENDING, event=self.event,
datetime=now() - timedelta(days=5), expires=now() + timedelta(days=5), total=46,
)
OrderPosition.objects.create(order=order, item=self.item1, voucher=v, price=Decimal('20.00'),
price_before_voucher=Decimal('23.00'))
assert v.budget_used() == Decimal('3.00')
order = Order.objects.create(
status=Order.STATUS_PAID, event=self.event,
datetime=now() - timedelta(days=5), expires=now() + timedelta(days=5), total=46,
)
OrderPosition.objects.create(order=order, item=self.item1, voucher=v, price=Decimal('20.00'),
price_before_voucher=Decimal('23.00'))
assert v.budget_used() == Decimal('6.00')
class OrderTestCase(BaseQuotaTestCase):
def setUp(self):