mirror of
https://github.com/pretix/pretix.git
synced 2026-05-07 15:34:02 +00:00
Allow to hide all sold out items
This commit is contained in:
@@ -1207,6 +1207,10 @@ class DisplaySettingsForm(SettingsForm):
|
||||
label=_("Show variations of a product expanded by default"),
|
||||
required=False
|
||||
)
|
||||
hide_sold_out = forms.BooleanField(
|
||||
label=_("Hide all products that are sold out"),
|
||||
required=False
|
||||
)
|
||||
frontpage_subevent_ordering = forms.ChoiceField(
|
||||
label=pgettext('subevent', 'Date ordering'),
|
||||
choices=[
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
{% bootstrap_field form.presale_has_ended_text layout="control" %}
|
||||
{% bootstrap_field form.voucher_explanation_text layout="control" %}
|
||||
{% bootstrap_field form.show_variations_expanded layout="control" %}
|
||||
{% bootstrap_field form.hide_sold_out layout="control" %}
|
||||
{% bootstrap_field form.meta_noindex layout="control" %}
|
||||
{% if form.frontpage_subevent_ordering %}
|
||||
{% bootstrap_field form.frontpage_subevent_ordering layout="control" %}
|
||||
|
||||
@@ -12,7 +12,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from pretix.base.forms.questions import (
|
||||
BaseInvoiceAddressForm, BaseQuestionsForm,
|
||||
)
|
||||
from pretix.base.models import ItemVariation
|
||||
from pretix.base.models import ItemVariation, Quota
|
||||
from pretix.base.models.tax import TAXED_ZERO
|
||||
from pretix.base.services.cart import CartError, error_messages
|
||||
from pretix.base.signals import validate_cart_addons
|
||||
@@ -171,9 +171,9 @@ class AddOnsForm(forms.Form):
|
||||
taxes=number_format(price.rate), taxname=price.name
|
||||
)
|
||||
|
||||
if avail[0] < 20:
|
||||
if avail[0] < Quota.AVAILABILITY_RESERVED:
|
||||
n += ' – {}'.format(_('SOLD OUT'))
|
||||
elif avail[0] < 100:
|
||||
elif avail[0] < Quota.AVAILABILITY_OK:
|
||||
n += ' – {}'.format(_('Currently unavailable'))
|
||||
else:
|
||||
if avail[1] is not None and item.do_show_quota_left:
|
||||
@@ -258,6 +258,9 @@ class AddOnsForm(forms.Form):
|
||||
choices = [('', _('no selection'), '')]
|
||||
for v in i.available_variations:
|
||||
cached_availability = v.check_quotas(subevent=subevent, _cache=quota_cache)
|
||||
if self.event.settings.hide_sold_out and cached_availability[0] < Quota.AVAILABILITY_RESERVED:
|
||||
continue
|
||||
|
||||
if v._subevent_quotas:
|
||||
self.vars_cache[v.pk] = v
|
||||
choices.append(
|
||||
@@ -295,6 +298,8 @@ class AddOnsForm(forms.Form):
|
||||
if not i._subevent_quotas:
|
||||
continue
|
||||
cached_availability = i.check_quotas(subevent=subevent, _cache=quota_cache)
|
||||
if self.event.settings.hide_sold_out and cached_availability[0] < Quota.AVAILABILITY_RESERVED:
|
||||
continue
|
||||
field = forms.BooleanField(
|
||||
label=self._label(self.event, i, cached_availability,
|
||||
override_price=item_price_override.get(i.pk)),
|
||||
|
||||
@@ -120,7 +120,10 @@ def get_grouped_items(event, subevent=None, voucher=None, channel='web', require
|
||||
max_per_order = item.max_per_order or int(event.settings.max_items_per_order)
|
||||
|
||||
if not item.has_variations:
|
||||
item._remove = not bool(item._subevent_quotas)
|
||||
item._remove = False
|
||||
if not bool(item._subevent_quotas):
|
||||
item._remove = True
|
||||
continue
|
||||
|
||||
if voucher and (voucher.allow_ignore_quota or voucher.block_quota):
|
||||
item.cached_availability = (
|
||||
@@ -131,6 +134,10 @@ def get_grouped_items(event, subevent=None, voucher=None, channel='web', require
|
||||
item.check_quotas(subevent=subevent, _cache=quota_cache, include_bundled=True)
|
||||
)
|
||||
|
||||
if event.settings.hide_sold_out and item.cached_availability[0] < Quota.AVAILABILITY_RESERVED:
|
||||
item._remove = True
|
||||
continue
|
||||
|
||||
item.order_max = min(
|
||||
item.cached_availability[1]
|
||||
if item.cached_availability[1] is not None else sys.maxsize,
|
||||
@@ -203,6 +210,10 @@ def get_grouped_items(event, subevent=None, voucher=None, channel='web', require
|
||||
)
|
||||
]
|
||||
|
||||
if event.settings.hide_sold_out:
|
||||
item.available_variations = [v for v in item.available_variations
|
||||
if v.cached_availability[0] >= Quota.AVAILABILITY_RESERVED]
|
||||
|
||||
if voucher and voucher.variation_id:
|
||||
item.available_variations = [v for v in item.available_variations
|
||||
if v.pk == voucher.variation_id]
|
||||
|
||||
Reference in New Issue
Block a user