# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2017-10-27 00:38
from __future__ import unicode_literals

# from django.core.management import call_command
from django.db import migrations, models
import django.db.models.deletion
import django.db.models.manager


class Migration(migrations.Migration):

    dependencies = [
        ('geodata', '0003_iati_to_aims_fks'),
        ('aims', '0049_transactionfinancials'),
    ]

    operations = [
        migrations.CreateModel(
            name='LocationGeodata',
            fields=[
                ('location', models.OneToOneField(on_delete=django.db.models.deletion.DO_NOTHING, primary_key=True, serialize=False, to='aims.Location')),
            ],
            options={
                'abstract': False,
                'managed': False,
            },
        ),
        migrations.CreateModel(
            name='TransactionValueLocationSector',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('dollars_for_location_for_sector', models.DecimalField(decimal_places=2, max_digits=15)),
            ],
            options={
                'abstract': False,
                'managed': False,
            },
        ),
        migrations.CreateModel(
            name='TransactionValueLocationView',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('dollars_for_location', models.DecimalField(decimal_places=2, max_digits=15)),
            ],
            options={
                'abstract': False,
                'managed': False,
            },
        ),
        migrations.AlterModelOptions(
            name='transactionfinancials',
            options={
                'abstract': False,
                'managed': False,
            },
        ),
        migrations.AlterModelManagers(
            name='activity',
            managers=[
                ('finance', django.db.models.manager.Manager()),
            ],
        ),
        migrations.AlterModelTable(
            name='transactionvalueusd',
            table=None,
        ),
        migrations.AddField(
            model_name='transactionvaluelocationview',
            name='activity',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='aims.Activity'),
        ),
        migrations.AddField(
            model_name='transactionvaluelocationview',
            name='location',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='aims.Location'),
        ),
        migrations.AddField(
            model_name='transactionvaluelocationview',
            name='region',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='geodata.Adm1Region'),
        ),
        migrations.AddField(
            model_name='transactionvaluelocationview',
            name='township',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='geodata.Adm2Region'),
        ),
        migrations.AddField(
            model_name='transactionvaluelocationview',
            name='transaction',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='aims.Transaction'),
        ),
        migrations.AddField(
            model_name='transactionvaluelocationsector',
            name='activity',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='aims.Activity'),
        ),
        migrations.AddField(
            model_name='transactionvaluelocationsector',
            name='category',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='aims.SectorCategory'),
        ),
        migrations.AddField(
            model_name='transactionvaluelocationsector',
            name='location',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='aims.Location'),
        ),
        migrations.AddField(
            model_name='transactionvaluelocationsector',
            name='region',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='geodata.Adm1Region'),
        ),
        migrations.AddField(
            model_name='transactionvaluelocationsector',
            name='sector',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='aims.Sector'),
        ),
        migrations.AddField(
            model_name='transactionvaluelocationsector',
            name='township',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='geodata.Adm2Region'),
        ),
        migrations.AddField(
            model_name='transactionvaluelocationsector',
            name='transaction',
            field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='aims.Transaction'),
        ),
        migrations.RunSQL('''SELECT setval(pg_get_serial_sequence('"aims_currency_exchange_rate"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "aims_currency_exchange_rate";'''),
        # migrations.RunSQL('''DELETE FROM aims_currency_exchange_rate WHERE id NOT IN(SELECT exchangerate_id FROM aims_transactionfinancials);''')
    ]
