Fix invalid handling of variations with quota-level vouchers

This commit is contained in:
Raphael Michel
2019-04-25 11:54:03 +02:00
parent 13bf975dd5
commit ef600ceddb
4 changed files with 81 additions and 1 deletions

View File

@@ -344,6 +344,8 @@ class Voucher(LoggedModel):
a variation).
"""
if self.quota_id:
if variation:
return variation.quotas.filter(pk=self.quota_id).exists()
return item.quotas.filter(pk=self.quota_id).exists()
if self.item_id and not self.variation_id:
return self.item_id == item.pk

View File

@@ -94,6 +94,11 @@ def get_grouped_items(event, subevent=None, voucher=None, channel='web'):
item_price_override = {}
var_price_override = {}
restrict_vars = set()
if voucher and voucher.quota_id:
# If a voucher is set to a specific quota, we need to filter out on that level
restrict_vars = set(voucher.quota.variations.all())
for item in items:
if voucher and voucher.item_id and voucher.variation_id:
# Restrict variations if the voucher only allows one
@@ -163,8 +168,11 @@ def get_grouped_items(event, subevent=None, voucher=None, channel='web'):
display_add_to_cart = display_add_to_cart or var.order_max > 0
item.available_variations = [
v for v in item.available_variations if v._subevent_quotas
v for v in item.available_variations if v._subevent_quotas and (
not voucher or not voucher.quota_id or v in restrict_vars
)
]
if voucher and voucher.variation_id:
item.available_variations = [v for v in item.available_variations
if v.pk == voucher.variation_id]