mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Merge pull request #201 from rixx/ticket165_reactivate_voucher
Fix #165 -- Reactivate voucher on cancelled orders
This commit is contained in:
@@ -7,7 +7,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from .base import LoggedModel
|
||||
from .event import Event
|
||||
from .items import Item, ItemVariation, Quota
|
||||
from .orders import CartPosition, OrderPosition
|
||||
from .orders import CartPosition, Order, OrderPosition
|
||||
|
||||
|
||||
def generate_code():
|
||||
@@ -161,10 +161,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:
|
||||
|
||||
@@ -142,7 +142,7 @@ def cancel_order(order, user=None):
|
||||
if isinstance(user, int):
|
||||
user = User.objects.get(pk=user)
|
||||
with order.event.lock():
|
||||
if order.status not in (Order.STATUS_PENDING, Order.STATUS_EXPIRED):
|
||||
if order.status != Order.STATUS_PENDING:
|
||||
raise OrderError(_('You cannot cancel this order.'))
|
||||
order.status = Order.STATUS_CANCELLED
|
||||
order.save()
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user