mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-29 08:02:24 +00:00
69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
# -*- 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
|
|
|
|
|
|
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,
|
|
)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('cotisations', '0039_documenttemplate'),
|
|
('preferences', '0056_4_radiusoption'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
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')),
|
|
],
|
|
options={
|
|
'verbose_name': 'cotisations options',
|
|
},
|
|
bases=(re2o.mixins.AclMixin, models.Model),
|
|
),
|
|
migrations.RunPython(initialize_invoice_template),
|
|
]
|