Cart API: Fix validation of subevent-bound vouchers

This commit is contained in:
Raphael Michel
2022-05-23 17:55:01 +02:00
parent 9ca2c8894d
commit 81c251208c

View File

@@ -142,7 +142,7 @@ class CartPositionCreateSerializer(I18nAwareModelSerializer):
if voucher and voucher.seat and voucher.seat != validated_data.get('seat'):
raise ValidationError('The specified voucher is not valid for this seat.')
if voucher and voucher.subevent_id and voucher.subevent_id != validated_data.get('subevent'):
if voucher and voucher.subevent_id and (not validated_data.get('subevent') or voucher.subevent_id != validated_data['subevent'].pk):
raise ValidationError('The specified voucher is not valid for this subevent.')
if voucher.valid_until is not None and voucher.valid_until < now():