Allow quotas to "close" when once full (#1344)

* Model

* Some UI

* API and logging

* Permission check

* Add tests

* Move option around
This commit is contained in:
Raphael Michel
2019-07-16 14:02:27 +02:00
committed by GitHub
parent c1e2fb36ba
commit a02ea45dba
16 changed files with 219 additions and 12 deletions

View File

@@ -518,6 +518,11 @@ class Event(EventMixin, LoggedModel):
vars = list(q.variations.all())
q.pk = None
q.event = self
q.cached_availability_state = None
q.cached_availability_number = None
q.cached_availability_paid_orders = None
q.cached_availability_time = None
q.closed = False
q.save()
for i in items:
if i.pk in item_map:

View File

@@ -1269,6 +1269,15 @@ class Quota(LoggedModel):
cached_availability_paid_orders = models.PositiveIntegerField(null=True, blank=True)
cached_availability_time = models.DateTimeField(null=True, blank=True)
close_when_sold_out = models.BooleanField(
verbose_name=_('Close this quota permanently once it is sold out'),
help_text=_('If you enable this, when the quota is sold out once, no more tickets will be sold, '
'even if tickets become available again through cancellations or expiring orders. Of course, '
'you can always re-open it manually.'),
default=False
)
closed = models.BooleanField(default=False)
objects = ScopedManager(organizer='event__organizer')
class Meta:
@@ -1334,6 +1343,11 @@ class Quota(LoggedModel):
count_waitinglist=count_waitinglist):
res = resp
if res[0] <= Quota.AVAILABILITY_ORDERED and self.close_when_sold_out and not self.closed:
self.closed = True
self.save(update_fields=['closed'])
self.log_action('pretix.event.quota.closed')
self.event.cache.delete('item_quota_cache')
rewrite_cache = count_waitinglist and (
not self.cache_is_hot(now_dt) or res[0] > self.cached_availability_state
@@ -1358,8 +1372,11 @@ class Quota(LoggedModel):
_cache['_count_waitinglist'] = count_waitinglist
return res
def _availability(self, now_dt: datetime=None, count_waitinglist=True):
def _availability(self, now_dt: datetime=None, count_waitinglist=True, ignore_closed=False):
now_dt = now_dt or now()
if self.closed and not ignore_closed:
return Quota.AVAILABILITY_ORDERED, 0
size_left = self.size
if size_left is None:
return Quota.AVAILABILITY_OK, None