Closed lucifurtun closed 4 years ago
Not really...
One place where you can do this right now is in the actual invoice template:
{% if document.meta.custom_template is True %}
{% include "_custom_invoice_template.html" %}
{% else %}
{% include "_invoice_template.html" %}
{% endif %}
Currently there is no place where you can hook into the logic that decides what template will be used for rendering.
You could override the get_template
method directly in your models.py
file, but it's not so nice:
from silver.models.documents import BillingDocumentBase
def get_template(doc, state=None):
// custom logic here
BillingDocumentBase.get_template = get_template
@bogdanpetrea, do you think it makes sense to have such feature exposed to the client?
If you'd be willing to describe your use case a bit, it might make sense.
@bogdanpetrea, sure. Let's say you have a Provider
that needs to issue invoices for some Customer
s using one template but for other Customer
s using some other template. How would you solve this issue?
If you know what customers require special treatment beforehand, you could just code it in your billing app (see my previous comment). You could override the get_template
method and read the template name that should be used from customer.meta
.
In both cases you are required to define the custom templates in your app beforehand. Otherwise it gets complicated... I don't know if there's any app that lets you submit templates via Django admin. The first thing that comes to mind is arbitrary code execution.
Is there any way to choose a specific template when adding a new invoice?