forked from CGM_Public/pretix_original
Product list: Fix edge case in dependent availabilities (Z#23243701)
This commit is contained in:
@@ -247,14 +247,15 @@ def prepare_item_list_for_shop(event, *, channel: SalesChannel, subevent=None, v
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if item.hidden_if_item_available:
|
if item.hidden_if_item_available:
|
||||||
|
time_available = item.hidden_if_item_available.is_available()
|
||||||
if item.hidden_if_item_available.has_variations:
|
if item.hidden_if_item_available.has_variations:
|
||||||
item._dependency_available = any(
|
item._dependency_available = any(
|
||||||
var.check_quotas(subevent=subevent, _cache=quota_cache, include_bundled=True)[0] == Quota.AVAILABILITY_OK
|
var.check_quotas(subevent=subevent, _cache=quota_cache, include_bundled=True)[0] == Quota.AVAILABILITY_OK
|
||||||
|
# is_available on variant is evaluated called by available_variations
|
||||||
for var in item.hidden_if_item_available.available_variations
|
for var in item.hidden_if_item_available.available_variations
|
||||||
)
|
) and time_available
|
||||||
else:
|
else:
|
||||||
q = item.hidden_if_item_available.check_quotas(subevent=subevent, _cache=quota_cache, include_bundled=True)
|
q = item.hidden_if_item_available.check_quotas(subevent=subevent, _cache=quota_cache, include_bundled=True)
|
||||||
time_available = item.hidden_if_item_available.is_available()
|
|
||||||
item._dependency_available = (q[0] == Quota.AVAILABILITY_OK) and time_available
|
item._dependency_available = (q[0] == Quota.AVAILABILITY_OK) and time_available
|
||||||
if item._dependency_available and item.hidden_if_item_available_mode == Item.UNAVAIL_MODE_HIDDEN:
|
if item._dependency_available and item.hidden_if_item_available_mode == Item.UNAVAIL_MODE_HIDDEN:
|
||||||
item._remove = True
|
item._remove = True
|
||||||
|
|||||||
@@ -744,6 +744,35 @@ class ItemDisplayTest(EventTestMixin, SoupTest):
|
|||||||
self.assertNotIn("SOLD OUT", doc.select("section:nth-of-type(1)")[0].text)
|
self.assertNotIn("SOLD OUT", doc.select("section:nth-of-type(1)")[0].text)
|
||||||
self.assertIn("Late-bird", doc.select("section:nth-of-type(1)")[0].text)
|
self.assertIn("Late-bird", doc.select("section:nth-of-type(1)")[0].text)
|
||||||
|
|
||||||
|
def test_hidden_if_item_available_variation_unavailable_by_time(self):
|
||||||
|
with scopes_disabled():
|
||||||
|
q = Quota.objects.create(event=self.event, name='Early-bird', size=10)
|
||||||
|
q2 = Quota.objects.create(event=self.event, name='Late-bird', size=10)
|
||||||
|
item_with_vars = Item.objects.create(event=self.event, name='Early-bird ticket', default_price=12)
|
||||||
|
v = item_with_vars.variations.create(
|
||||||
|
value='Regular', active=True,
|
||||||
|
)
|
||||||
|
item2 = Item.objects.create(event=self.event, name='Late-bird ticket', default_price=12,
|
||||||
|
hidden_if_item_available=item_with_vars)
|
||||||
|
q.items.add(item_with_vars)
|
||||||
|
q.variations.add(v)
|
||||||
|
q2.items.add(item2)
|
||||||
|
|
||||||
|
self.event.settings.hide_sold_out = True
|
||||||
|
doc = self.get_doc('/%s/%s/' % (self.orga.slug, self.event.slug))
|
||||||
|
self.assertIn("Early-bird", doc.select("section:nth-of-type(1)")[0].text)
|
||||||
|
self.assertNotIn("SOLD OUT", doc.select("section:nth-of-type(1)")[0].text)
|
||||||
|
self.assertNotIn("Late-bird", doc.select("section:nth-of-type(1)")[0].text)
|
||||||
|
|
||||||
|
item_with_vars.available_until = now() - datetime.timedelta(days=3)
|
||||||
|
item_with_vars.available_until_mode = "hide"
|
||||||
|
item_with_vars.save()
|
||||||
|
|
||||||
|
doc = self.get_doc('/%s/%s/' % (self.orga.slug, self.event.slug))
|
||||||
|
self.assertNotIn("Early-bird", doc.select("section:nth-of-type(1)")[0].text)
|
||||||
|
self.assertNotIn("SOLD OUT", doc.select("section:nth-of-type(1)")[0].text)
|
||||||
|
self.assertIn("Late-bird", doc.select("section:nth-of-type(1)")[0].text)
|
||||||
|
|
||||||
def test_bundle_sold_out(self):
|
def test_bundle_sold_out(self):
|
||||||
with scopes_disabled():
|
with scopes_disabled():
|
||||||
q = Quota.objects.create(event=self.event, name='Quota', size=2)
|
q = Quota.objects.create(event=self.event, name='Quota', size=2)
|
||||||
|
|||||||
Reference in New Issue
Block a user