Do not allow customers to cancel checked-in orders

This commit is contained in:
Raphael Michel
2019-01-21 09:04:06 +01:00
parent cdea6eb55e
commit 3703fbcacf
2 changed files with 21 additions and 3 deletions

View File

@@ -395,8 +395,14 @@ class Order(LockModel, LoggedModel):
"""
Returns whether or not this order can be canceled by the user.
"""
positions = list(self.positions.all().select_related('item'))
cancelable = all([op.item.allow_cancel for op in positions])
from .checkin import Checkin
positions = list(
self.positions.all().annotate(
has_checkin=Exists(Checkin.objects.filter(position_id=OuterRef('pk')))
).select_related('item')
)
cancelable = all([op.item.allow_cancel and not op.has_checkin for op in positions])
if not cancelable or not positions:
return False
if self.user_cancel_deadline and now() > self.user_cancel_deadline: