Allow to hide a product unless a specific quota is sold out (#1351)

* Allow to hide a product unless a specific quota is sold out

* Fix required property

* Add API property and copy between events
This commit is contained in:
Raphael Michel
2019-07-25 16:14:24 +02:00
committed by GitHub
parent 2dd75ea252
commit e83e8cdcc0
16 changed files with 250 additions and 8 deletions

View File

@@ -516,6 +516,7 @@ class Event(EventMixin, LoggedModel):
for q in Quota.objects.filter(event=other, subevent__isnull=True).prefetch_related('items', 'variations'):
items = list(q.items.all())
vars = list(q.variations.all())
oldid = q.pk
q.pk = None
q.event = self
q.cached_availability_state = None
@@ -529,6 +530,7 @@ class Event(EventMixin, LoggedModel):
q.items.add(item_map[i.pk])
for v in vars:
q.variations.add(variation_map[v.pk])
self.items.filter(hidden_if_available_id=oldid).update(hidden_if_available=q)
question_map = {}
for q in Question.objects.filter(event=other).prefetch_related('items', 'options'):

View File

@@ -334,6 +334,17 @@ class Item(LoggedModel):
null=True, blank=True,
help_text=_('This product will not be sold after the given date.')
)
hidden_if_available = models.ForeignKey(
'Quota',
null=True, blank=True,
on_delete=models.SET_NULL,
verbose_name=_("Only show after sellout of"),
help_text=_("If you select a quota here, this product will only be shown when that quota is "
"unavailable. If combined with the option to hide sold-out products, this allows you to "
"swap out products for more expensive ones once they are sold out. There might be a short period "
"in which both products are visible while all tickets in the referenced quota are reserved, "
"but not yet sold.")
)
require_voucher = models.BooleanField(
verbose_name=_('This product can only be bought using a voucher.'),
default=False,