mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Meilleure gestion des default pour les templates invoice et voucher
This commit is contained in:
parent
1fcf90b698
commit
f43b985966
3 changed files with 24 additions and 37 deletions
|
@ -797,8 +797,8 @@ main_function() {
|
|||
|
||||
update )
|
||||
install_requirements
|
||||
update_django
|
||||
copy_templates_files
|
||||
update_django
|
||||
;;
|
||||
|
||||
copy-templates-files )
|
||||
|
|
|
@ -1,48 +1,16 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2019-01-03 19:56
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
from django.core.files import File
|
||||
from django.conf import settings
|
||||
import re2o.mixins
|
||||
import preferences.models
|
||||
|
||||
|
||||
def initialize_invoice_template(apps, schema_editor):
|
||||
CotisationsOption = apps.get_model('preferences', 'CotisationsOption')
|
||||
DocumentTemplate = apps.get_model('cotisations', 'DocumentTemplate')
|
||||
invoice_path = os.path.join(
|
||||
settings.BASE_DIR,
|
||||
"cotisations",
|
||||
"templates",
|
||||
"cotisations",
|
||||
"factures.tex"
|
||||
)
|
||||
voucher_path = os.path.join(
|
||||
settings.BASE_DIR,
|
||||
"cotisations",
|
||||
"templates",
|
||||
"cotisations",
|
||||
"voucher.tex"
|
||||
)
|
||||
with open(invoice_path) as f:
|
||||
tpl_invoice, _ = DocumentTemplate.objects.get_or_create(
|
||||
name="Re2o default invoice",
|
||||
)
|
||||
tpl_invoice.template.save('default_invoice.tex', File(f))
|
||||
tpl_invoice.save()
|
||||
with open(voucher_path) as f:
|
||||
tpl_voucher, _ = DocumentTemplate.objects.get_or_create(
|
||||
name="Re2o default voucher",
|
||||
)
|
||||
tpl_voucher.template.save('default_voucher.tex', File(f))
|
||||
tpl_voucher.save()
|
||||
CotisationsOption.objects.create(
|
||||
invoice_template=tpl_invoice,
|
||||
voucher_template=tpl_voucher,
|
||||
)
|
||||
CotisationsOption.objects.get_or_create()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -57,8 +25,8 @@ class Migration(migrations.Migration):
|
|||
name='CotisationsOption',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('invoice_template', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='invoice_template', to='cotisations.DocumentTemplate', verbose_name='Template for invoices')),
|
||||
('voucher_template', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='voucher_template', to='cotisations.DocumentTemplate', verbose_name='Template for subscription voucher')),
|
||||
('invoice_template', models.OneToOneField(default=preferences.models.default_invoice,on_delete=django.db.models.deletion.PROTECT, related_name='invoice_template', to='cotisations.DocumentTemplate', verbose_name='Template for invoices')),
|
||||
('voucher_template', models.OneToOneField(default=preferences.models.default_voucher, on_delete=django.db.models.deletion.PROTECT, related_name='voucher_template', to='cotisations.DocumentTemplate', verbose_name='Template for subscription voucher')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'cotisations options',
|
||||
|
|
|
@ -35,6 +35,7 @@ from django.forms import ValidationError
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
import machines.models
|
||||
import cotisations.models
|
||||
|
||||
from re2o.mixins import AclMixin
|
||||
from re2o.aes_field import AESEncryptedField
|
||||
|
@ -694,6 +695,22 @@ class RadiusOption(AclMixin, PreferencesModel):
|
|||
)
|
||||
|
||||
|
||||
def default_invoice():
|
||||
tpl, _ = cotisations.models.DocumentTemplate.objects.get_or_create(
|
||||
name="Re2o default invoice",
|
||||
template="templates/default_invoice.tex"
|
||||
)
|
||||
return tpl.id
|
||||
|
||||
|
||||
def default_voucher():
|
||||
tpl, _ = cotisations.models.DocumentTemplate.objects.get_or_create(
|
||||
name="Re2o default voucher",
|
||||
template="templates/default_voucher.tex"
|
||||
)
|
||||
return tpl.id
|
||||
|
||||
|
||||
class CotisationsOption(AclMixin, PreferencesModel):
|
||||
class Meta:
|
||||
verbose_name = _("cotisations options")
|
||||
|
@ -703,10 +720,12 @@ class CotisationsOption(AclMixin, PreferencesModel):
|
|||
verbose_name=_("Template for invoices"),
|
||||
related_name="invoice_template",
|
||||
on_delete=models.PROTECT,
|
||||
default=default_invoice,
|
||||
)
|
||||
voucher_template = models.OneToOneField(
|
||||
'cotisations.DocumentTemplate',
|
||||
verbose_name=_("Template for subscription voucher"),
|
||||
related_name="voucher_template",
|
||||
on_delete=models.PROTECT,
|
||||
default=default_voucher,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue