Fix #489 -- Handle Vouchers With Unavailable Items (#659)

* Fix #489 -- Handle Vouchers With Unavailable Items

* Add regression test
This commit is contained in:
Ben Hagan
2017-11-01 16:05:10 -05:00
committed by Raphael Michel
parent 82d289cfcf
commit 764b9dda7e
3 changed files with 14 additions and 1 deletions

View File

@@ -61,6 +61,8 @@ error_messages = {
'cart if you want to use it for a different product.'),
'voucher_expired': _('This voucher is expired.'),
'voucher_invalid_item': _('This voucher is not valid for this product.'),
'voucher_item_not_available': _(
'Your voucher is valid for a product that is currently not for sale.'),
'voucher_invalid_subevent': pgettext_lazy('subevent', 'This voucher is not valid for this event date.'),
'voucher_required': _('You need a valid voucher code to order this product.'),
'inactive_subevent': pgettext_lazy('subevent', 'The selected event date is not active.'),

View File

@@ -395,6 +395,8 @@ class RedeemView(NoSearchIndexViewMixin, EventViewMixin, TemplateView):
err = error_messages['voucher_redeemed']
if self.voucher.valid_until is not None and self.voucher.valid_until < now():
err = error_messages['voucher_expired']
if self.voucher.item is not None and self.voucher.item.is_available() is False:
err = error_messages['voucher_item_not_available']
redeemed_in_carts = CartPosition.objects.filter(
Q(voucher=self.voucher) & Q(event=request.event) &