Move bulk_create logic during bulk voucher creation

This commit is contained in:
Raphael Michel
2020-02-09 12:17:48 +01:00
parent 82e40ce664
commit 7acee9458d
2 changed files with 7 additions and 4 deletions

View File

@@ -388,4 +388,9 @@ class VoucherBulkForm(VoucherForm):
del data['codes']
objs.append(obj)
Voucher.objects.bulk_create(objs)
objs = []
for v in event.vouchers.filter(code__in=self.cleaned_data['codes']):
# We need to query them again as bulk_create does not fill in .pk values on databases
# other than PostgreSQL
objs.append(v)
return objs

View File

@@ -320,11 +320,9 @@ class VoucherBulkCreate(EventPermissionRequiredMixin, CreateView):
@transaction.atomic
def form_valid(self, form):
log_entries = []
form.save(self.request.event)
# We need to query them again as form.save() uses bulk_create which does not fill in .pk values on databases
# other than PostgreSQL
objs = form.save(self.request.event)
voucherids = []
for v in self.request.event.vouchers.filter(code__in=form.cleaned_data['codes']):
for v in objs:
log_entries.append(
v.log_action('pretix.voucher.added', data=form.cleaned_data, user=self.request.user, save=False)
)