silverapp / silver

Automated billing and payments for Django with a REST API
https://www.presslabs.com/code/silver/
Other
301 stars 80 forks source link

Multiple invoice templates #658

Closed lucifurtun closed 4 years ago

lucifurtun commented 5 years ago

Is there any way to choose a specific template when adding a new invoice?

bogdanpetrea commented 5 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
lucifurtun commented 5 years ago

@bogdanpetrea, do you think it makes sense to have such feature exposed to the client?

bogdanpetrea commented 5 years ago

If you'd be willing to describe your use case a bit, it might make sense.

lucifurtun commented 5 years ago

@bogdanpetrea, sure. Let's say you have a Provider that needs to issue invoices for some Customers using one template but for other Customers using some other template. How would you solve this issue?

bogdanpetrea commented 5 years ago

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.