forked from CGM_Public/pretix_original
Fix initial value in voucher form
This commit is contained in:
@@ -77,6 +77,23 @@ class VoucherForm(I18nModelForm):
|
||||
del self.fields['subevent']
|
||||
|
||||
choices = []
|
||||
if 'itemvar' in initial:
|
||||
iv = initial.get('itemvar', '')
|
||||
if iv.startswith('q-'):
|
||||
q = self.instance.event.quotas.get(pk=iv[2:])
|
||||
choices.append(('q-%d' % q.pk, _('Any product in quota "{quota}"').format(quota=q)))
|
||||
elif '-' in iv:
|
||||
itemid, varid = iv.split('-')
|
||||
i = self.instance.event.items.get(pk=itemid)
|
||||
v = i.variations.get(pk=varid)
|
||||
choices.append(('%d-%d' % (i.pk, v.pk), '%s – %s' % (i.name, v.value)))
|
||||
else:
|
||||
i = self.instance.event.items.get(pk=iv)
|
||||
if i.variations.exists():
|
||||
choices.append((str(i.pk), _('{product} – Any variation').format(product=i.name)))
|
||||
else:
|
||||
choices.append((str(i.pk), str(i.name)))
|
||||
|
||||
self.fields['itemvar'].choices = choices
|
||||
self.fields['itemvar'].widget = Select2ItemVarQuota(
|
||||
attrs={
|
||||
|
||||
@@ -45,7 +45,7 @@ class Select2ItemVarQuotaMixin(Select2Mixin):
|
||||
yield self.create_option(
|
||||
None,
|
||||
value[0],
|
||||
value[0],
|
||||
dict(self.choices)[value[0]],
|
||||
True,
|
||||
0,
|
||||
subindex=None,
|
||||
|
||||
Reference in New Issue
Block a user