8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-22 23:13:46 +00:00

Enable template selection for invoices.

This commit is contained in:
Hugo LEVY-FALK 2019-01-03 22:34:45 +01:00
parent 6fdf8a0406
commit 0a8335c375
7 changed files with 52 additions and 1 deletions

View file

@ -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
)

View file

@ -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:

View file

@ -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,
)

View file

@ -346,6 +346,25 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</table>
</div>
</div>
<div class="panel panel-default" id="cotisation">
<div class="panel-heading" data-toggle="collapse" href="#collapse_cotisation">
<h4 class="panel-title">
<a><i class="fa fa-eur"></i> {% trans "Cotisation's options" %}</a>
</h4>
</div>
<div id="collapse_cotisation" class="panel-collapse panel-body collapse">
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'CotisationsOption' %}">
<i class="fa fa-edit"></i>
</a>
<table class="table table-striped">
<tr>
<th>{% trans "Invoices' template" %}</th>
<td>{{ cotisationsoptions.invoice_template }}</td>
</tr>
</table>
</div>
</div>
<div class="panel panel-default" id="mail">
<div class="panel-heading" data-toggle="collapse" href="#collapse_mail">

View file

@ -71,6 +71,11 @@ urlpatterns = [
views.edit_options,
name='edit-options'
),
url(
r'^edit_options/(?P<section>CotisationsOption)$',
views.edit_options,
name='edit-options'
),
url(r'^add_service/$', views.add_service, name='add-service'),
url(
r'^edit_service/(?P<serviceid>[0-9]+)$',

View file

@ -64,6 +64,7 @@ from .models import (
RadiusKey,
SwitchManagementCred,
RadiusOption,
CotisationsOption,
)
from . import models
from . import forms
@ -88,6 +89,7 @@ def display_options(request):
radiuskey_list = RadiusKey.objects.all()
switchmanagementcred_list = SwitchManagementCred.objects.all()
radiusoptions, _ = RadiusOption.objects.get_or_create()
cotisationsoptions, _created = CotisationsOption.objects.get_or_create()
return form({
'useroptions': useroptions,
'machineoptions': machineoptions,
@ -102,6 +104,7 @@ def display_options(request):
'radiuskey_list' : radiuskey_list,
'switchmanagementcred_list': switchmanagementcred_list,
'radiusoptions' : radiusoptions,
'cotisationsoptions': cotisationsoptions,
}, 'preferences/display_preferences.html', request)

View file

@ -120,6 +120,7 @@ TEMPLATES = [
'DIRS': [
# Use only absolute paths with '/' delimiters even on Windows
os.path.join(BASE_DIR, 'templates').replace('\\', '/'),
os.path.join(BASE_DIR, 'media', 'templates').replace('\\', '/'),
],
'APP_DIRS': True,
'OPTIONS': {