Voucher bulk creation: Fix vouchers being created in wrong order

This commit is contained in:
Raphael Michel
2023-05-25 10:25:05 +02:00
parent c8ef681cc3
commit a3202ffc71
2 changed files with 4 additions and 6 deletions

View File

@@ -35,7 +35,7 @@ def vouchers_send(event: Event, vouchers: list, subject: str, message: str, reci
for ir, r in enumerate(recipients): for ir, r in enumerate(recipients):
voucher_list = [] voucher_list = []
for i in range(r['number']): for i in range(r['number']):
voucher_list.append(vouchers.pop()) voucher_list.append(vouchers.pop(0))
with language(event.settings.locale): with language(event.settings.locale):
email_context = get_email_context(event=event, name=r.get('name') or '', email_context = get_email_context(event=event, name=r.get('name') or '',
voucher_list=[v.code for v in voucher_list]) voucher_list=[v.code for v in voucher_list])

View File

@@ -521,13 +521,11 @@ class VoucherFormTest(SoupTestMixin, TransactionTestCase):
'send': 'on', 'send': 'on',
'send_subject': 'Your voucher', 'send_subject': 'Your voucher',
'send_message': 'Voucher list: {voucher_list}', 'send_message': 'Voucher list: {voucher_list}',
'send_recipients': 'foo@example.com\nfoo@example.net' 'send_recipients': 'foo@example.com\nbar@example.net'
}) })
assert len(djmail.outbox) == 2 assert len(djmail.outbox) == 2
assert len([m for m in djmail.outbox if m.to == ['foo@example.com']]) == 1 assert len([m for m in djmail.outbox if 'ABCDE' in m.body and m.to == ['foo@example.com']]) == 1
assert len([m for m in djmail.outbox if m.to == ['foo@example.net']]) == 1 assert len([m for m in djmail.outbox if 'DEFGH' in m.body and m.to == ['bar@example.net']]) == 1
assert len([m for m in djmail.outbox if 'ABCDE' in m.body]) == 1
assert len([m for m in djmail.outbox if 'DEFGH' in m.body]) == 1
def test_create_bulk_send_csv(self): def test_create_bulk_send_csv(self):
self._create_bulk_vouchers({ self._create_bulk_vouchers({