Fix voucher queryset (again)

This commit is contained in:
Raphael Michel
2019-07-09 18:02:08 +02:00
parent eef713816e
commit e7baca952b

View File

@@ -168,15 +168,16 @@ def filter_available(qs, channel='web', voucher=None, allow_addons=False):
) )
if not allow_addons: if not allow_addons:
q &= Q(Q(category__isnull=True) | Q(category__is_addon=False)) q &= Q(Q(category__isnull=True) | Q(category__is_addon=False))
qs = qs.filter(q)
vouchq = Q(hide_without_voucher=False) if voucher:
if voucher and voucher.show_hidden_items:
if voucher.item_id: if voucher.item_id:
vouchq = Q(pk=voucher.item_id) q &= Q(pk=voucher.item_id)
elif voucher.quota_id: elif voucher.quota_id:
vouchq = Q(quotas__in=[voucher.quota_id]) q &= Q(quotas__in=[voucher.quota_id])
return qs.filter(vouchq) if not voucher or not voucher.show_hidden_items:
q &= Q(hide_without_voucher=False)
return qs.filter(q)
class ItemQuerySet(models.QuerySet): class ItemQuerySet(models.QuerySet):