Writing an invoice renderer plugin
An invoice renderer controls how invoice files are built. The creation of such a plugin is very similar to creating an export output.
Please read Creating a plugin first, if you haven’t already.
Output registration
The invoice renderer API does not make a lot of usage from signals, however, it
does use a signal to get a list of all available invoice renderers. Your plugin
should listen for this signal and return the subclass of eventyay.base.invoice.BaseInvoiceRenderer
that we’ll provide in this plugin:
1from django.dispatch import receiver
2
3from eventyay.base.signals import register_invoice_renderers
4
5
6@receiver(register_invoice_renderers, dispatch_uid="output_custom")
7def register_invoice_renderers(sender, **kwargs):
8 from .invoice import MyInvoiceRenderer
9 return MyInvoiceRenderer
The renderer class
- class eventyay.base.invoice.BaseInvoiceRenderer
The central object of each invoice renderer is the subclass of
BaseInvoiceRenderer.- BaseInvoiceRenderer.event
The default constructor sets this property to the event we are currently working for.
- identifier
A short and unique identifier for this invoice renderer.
This is an abstract attribute, you must override this!
- verbose_name
A human-readable name for this invoice renderer.
This is an abstract attribute, you must override this!
- generate(invoice)
Generate the invoice file.
- Parameters:
invoice – The invoice to generate a file for.
- Returns:
A tuple of (filename, content_type, file_content)
Helper class for reportlab-base renderers
All PDF rendering that ships with eventyay is based on reportlab. We recommend to read the reportlab User Guide to understand all the concepts used here.
If you want to implement a renderer that also uses report lab, this helper class might be convenient to you:
- class eventyay.base.invoice.BaseReportlabInvoiceRenderer
- BaseReportlabInvoiceRenderer.pagesize
- BaseReportlabInvoiceRenderer.left_margin
- BaseReportlabInvoiceRenderer.right_margin
- BaseReportlabInvoiceRenderer.top_margin
- BaseReportlabInvoiceRenderer.bottom_margin
- BaseReportlabInvoiceRenderer.doc_template_class
- BaseReportlabInvoiceRenderer.invoice
- _init()
Initialize the renderer.
- _get_stylesheet()
Get the reportlab stylesheet.
- _register_fonts()
Register custom fonts with reportlab.
- _on_first_page(canvas, doc)
Callback for rendering the first page.
- _on_other_page(canvas, doc)
Callback for rendering other pages.
- _get_first_page_frames(doc)
Get the frames for the first page.
- _get_other_page_frames(doc)
Get the frames for other pages.
- _build_doc(fhandle, story)
Build the document.