Voucher creation: Fix crash in validation (PRETIXEU-8GF)

This commit is contained in:
Raphael Michel
2023-06-02 15:52:25 +02:00
parent eb3eca45b5
commit 35d2a73f75

View File

@@ -386,17 +386,18 @@ class VoucherBulkForm(VoucherForm):
def clean(self): def clean(self):
data = super().clean() data = super().clean()
vouchers = self.instance.event.vouchers.annotate( if 'codes' in data:
code_upper=Upper('code') vouchers = self.instance.event.vouchers.annotate(
).filter(code_upper__in=[c.upper() for c in data['codes']]) code_upper=Upper('code')
if vouchers.exists(): ).filter(code_upper__in=[c.upper() for c in data['codes']])
raise ValidationError(_('A voucher with one of these codes already exists.')) if vouchers.exists():
raise ValidationError(_('A voucher with one of these codes already exists.'))
codes_seen = set() codes_seen = set()
for c in data['codes']: for c in data['codes']:
if c in codes_seen: if c in codes_seen:
raise ValidationError(_('The voucher code {code} appears in your list twice.').format(code=c)) raise ValidationError(_('The voucher code {code} appears in your list twice.').format(code=c))
codes_seen.add(c) codes_seen.add(c)
if data.get('send') and not all([data.get('send_subject'), data.get('send_message'), data.get('send_recipients')]): if data.get('send') and not all([data.get('send_subject'), data.get('send_message'), data.get('send_recipients')]):
raise ValidationError(_('If vouchers should be sent by email, subject, message and recipients need to be specified.')) raise ValidationError(_('If vouchers should be sent by email, subject, message and recipients need to be specified.'))