Make vouchers reusable upon cancelation of an Order

Refs #165.
This commit is contained in:
Tobias Kunze
2016-08-08 18:50:16 +02:00
parent 68967fbfda
commit 5667866c9d
2 changed files with 8 additions and 1 deletions

View File

@@ -162,10 +162,12 @@ class Voucher(LoggedModel):
def is_ordered(self) -> int:
"""
Returns whether an order position exists that uses this voucher.
Returns whether a non-canceled order position exists that uses this voucher.
"""
return OrderPosition.objects.filter(
voucher=self
).exclude(
order__status=Order.STATUS_CANCELLED
).exists()
def is_in_cart(self) -> int:

View File

@@ -152,6 +152,11 @@ def cancel_order(order, user=None):
if i:
generate_cancellation(i)
for position in order.positions.all():
if position.voucher:
position.voucher.redeemed = False
position.voucher.save()
return order