0031_custom_invoice.py 2.9 KB
Newer Older
Levy--Falk Hugo's avatar
Levy--Falk Hugo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-21 20:01
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import re2o.field_permissions
import re2o.mixins


def reattribute_ids(apps, schema_editor):
    Facture = apps.get_model('cotisations', 'Facture')
    BaseInvoice = apps.get_model('cotisations', 'BaseInvoice')

    for f in Facture.objects.all():
        base = BaseInvoice.objects.create(id=f.pk, date=f.date)
        f.baseinvoice_ptr = base
        f.save()

class Migration(migrations.Migration):

    dependencies = [
        ('cotisations', '0030_custom_payment'),
    ]

    operations = [
        migrations.CreateModel(
            name='BaseInvoice',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date', models.DateTimeField(auto_now_add=True, verbose_name='Date')),
            ],
            bases=(re2o.mixins.RevMixin, re2o.mixins.AclMixin, re2o.field_permissions.FieldPermissionModelMixin, models.Model),
        ),
        migrations.CreateModel(
            name='CustomInvoice',
            fields=[
                ('baseinvoice_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='cotisations.BaseInvoice')),
                ('recipient', models.CharField(max_length=255, verbose_name='Recipient')),
                ('payment', models.CharField(max_length=255, verbose_name='Payment type')),
                ('address', models.CharField(max_length=255, verbose_name='Address')),
                ('paid', models.BooleanField(verbose_name='Paid')),
            ],
            bases=('cotisations.baseinvoice',),
            options={'permissions': (('view_custom_invoice', 'Can view a custom invoice'),)},
        ),
        migrations.AddField(
            model_name='facture',
            name='baseinvoice_ptr',
            field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='cotisations.BaseInvoice', null=True),
            preserve_default=False,
        ),
        migrations.RunPython(reattribute_ids),
        migrations.AlterField(
            model_name='vente',
            name='facture',
            field=models.ForeignKey(on_delete=models.CASCADE, verbose_name='Invoice', to='cotisations.BaseInvoice')
        ),
        migrations.RemoveField(
            model_name='facture',
            name='id',
        ),
        migrations.RemoveField(
            model_name='facture',
            name='date',
        ),
        migrations.AlterField(
            model_name='facture',
            name='baseinvoice_ptr',
            field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='cotisations.BaseInvoice'),
        )
    ]