diff --git a/cotisations/tex.py b/cotisations/tex.py index 873c9346..b253d12b 100644 --- a/cotisations/tex.py +++ b/cotisations/tex.py @@ -40,6 +40,7 @@ from django.utils.text import slugify from django.utils.translation import ugettext_lazy as _ from re2o.mixins import AclMixin, RevMixin +from preferences.models import CotisationsOption TEMP_PREFIX = getattr(settings, 'TEX_TEMP_PREFIX', 'render_tex-') @@ -73,6 +74,7 @@ def render_invoice(_request, ctx={}): Render an invoice using some available information such as the current date, the user, the articles, the prices, ... """ + options, _ = CotisationsOption.objects.get_or_create() is_estimate = ctx.get('is_estimate', False) filename = '_'.join([ 'cost_estimate' if is_estimate else 'invoice', @@ -82,7 +84,8 @@ def render_invoice(_request, ctx={}): str(ctx.get('DATE', datetime.now()).month), str(ctx.get('DATE', datetime.now()).day), ]) - r = render_tex(_request, 'cotisations/factures.tex', ctx) + templatename = options.invoice_template.template.name.split('/')[-1] + r = render_tex(_request, templatename, ctx) r['Content-Disposition'] = 'attachment; filename="{name}.pdf"'.format( name=filename ) diff --git a/preferences/forms.py b/preferences/forms.py index 3d461ef2..d8e762e1 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -43,6 +43,7 @@ from .models import ( RadiusKey, SwitchManagementCred, RadiusOption, + CotisationsOption ) from topologie.models import Switch @@ -253,6 +254,13 @@ class EditRadiusOptionForm(ModelForm): return cleaned_data +class EditCotisationsOptionForm(ModelForm): + """Edition forms for Cotisations options""" + class Meta: + model = CotisationsOption + fields = '__all__' + + class ServiceForm(ModelForm): """Edition, ajout de services sur la page d'accueil""" class Meta: diff --git a/preferences/models.py b/preferences/models.py index daeb4a05..781107af 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -687,3 +687,15 @@ class RadiusOption(AclMixin, PreferencesModel): null=True ) + +class CotisationsOption(AclMixin, PreferencesModel): + class Meta: + verbose_name = _("cotisations options") + + invoice_template = models.OneToOneField( + 'cotisations.DocumentTemplate', + verbose_name=_("Template for invoices"), + related_name="invoice_template", + on_delete=models.PROTECT, + ) + diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index 50b2b647..b0fd8dd8 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -346,6 +346,25 @@ with this program; if not, write to the Free Software Foundation, Inc., +
{% trans "Invoices' template" %} | +{{ cotisationsoptions.invoice_template }} | +
---|