Skip to content

Important: Voucher functionality not working

For example: http://localhost:8001/mail_templates/print_vouchers?voucher_id=1, rises this error: error_vouchers.pdf

I solved it in the branch hotfix/voucher_templates with the following change:

@@ -86,10 +88,16 @@ def generate(request, mail_template_id, instance_id):
 def generate_for_vouchers(request):
     ids = request.GET.get('voucher_id', '').split(',')
     vouchers = []
+    languages = []
     for voucher_id in ids:
         if voucher_id.isdigit():
-            vouchers.append(Voucher.objects.get(pk=int(voucher_id)))
-    templates = MailTemplate.get_voucher_mail_templates([])[0]
+            voucher = Voucher.objects.get(pk=int(voucher_id))
+            vouchers.append(voucher)
+            try:
+                languages.extend(voucher.study_subject.subject.languages.all())
+            except: #if no languages or no subject or no study subject
+                continue
+    templates = MailTemplate.get_voucher_mail_templates(list(set(languages)))[0]

     output_stream = StringIO.StringIO()

I tested this template: template_pdp_final.docx and both the process and merge (concatenation) of templates work fine. vouchers_.docx

Also:

  • If no voucher is selected and error raises.
  • If there is no voucher in the language of the subject, then an error raises.
Edited by Carlos Vega