Swappable invoice renderers

This commit is contained in:
Raphael Michel
2017-07-07 11:16:07 +02:00
parent 95e716b8ce
commit 6e65ae5306
12 changed files with 564 additions and 279 deletions

View File

@@ -436,6 +436,11 @@ class InvoiceSettingsForm(SettingsForm):
('paid', _('Automatically on payment')),
)
)
invoice_renderer = forms.ChoiceField(
label=_("Invoice style"),
required=True,
choices=[]
)
invoice_address_from = forms.CharField(
widget=forms.Textarea(attrs={'rows': 5}), required=False,
label=_("Your address"),
@@ -472,6 +477,13 @@ class InvoiceSettingsForm(SettingsForm):
help_text=_('We will show your logo with a maximal height and width of 2.5 cm.')
)
def __init__(self, *args, **kwargs):
event = kwargs.get('obj')
super().__init__(*args, **kwargs)
self.fields['invoice_renderer'].choices = [
(r.identifier, r.verbose_name) for r in event.get_invoice_renderers().values()
]
class MailSettingsForm(SettingsForm):
mail_prefix = forms.CharField(

View File

@@ -12,6 +12,7 @@
{% bootstrap_field form.invoice_address_vatid layout="horizontal" %}
{% bootstrap_field form.invoice_numbers_consecutive layout="horizontal" %}
{% bootstrap_field form.invoice_generate layout="horizontal" %}
{% bootstrap_field form.invoice_renderer layout="horizontal" %}
{% bootstrap_field form.invoice_language layout="horizontal" %}
{% bootstrap_field form.invoice_address_from layout="horizontal" %}
{% bootstrap_field form.invoice_introductory_text layout="horizontal" %}

View File

@@ -310,9 +310,9 @@ class InvoicePreview(EventPermissionRequiredMixin, View):
permission = 'can_change_event_settings'
def get(self, request, *args, **kwargs):
pdf = build_preview_invoice_pdf(request.event)
resp = HttpResponse(pdf, content_type='application/pdf')
resp['Content-Disposition'] = 'attachment; filename="invoice-preview.pdf"'
fname, ftype, fcontent = build_preview_invoice_pdf(request.event)
resp = HttpResponse(fcontent, content_type=ftype)
resp['Content-Disposition'] = 'attachment; filename="{}"'.format(fname)
return resp