# Generated by Django 3.1.3 on 2022-02-10 13:02

from django.db import migrations, models


def migrate_actions(apps, schema_editor):
    CompensationAction = apps.get_model('compensation', 'CompensationAction')
    actions = CompensationAction.objects.all()

    for action in actions:
        action_type = action.action_type or []
        action.action_type_tmp.set([action_type])
        action.save()

        if not action.action_type_tmp.count() > 0:
            raise ValueError("Migration of actions did not work! Stoped before data loss!")


class Migration(migrations.Migration):

    dependencies = [
        ('codelist', '0001_initial'),
        ('compensation', '0003_auto_20220202_0846'),
    ]

    operations = [
        migrations.AddField(
            model_name='compensationaction',
            name='action_type_tmp',
            field=models.ManyToManyField(blank=True, limit_choices_to={'code_lists__in': [1026], 'is_archived': False, 'is_selectable': True}, related_name='_compensationaction_action_type_+', to='codelist.KonovaCode'),
        ),
        migrations.RunPython(migrate_actions),
        migrations.RemoveField(
            model_name='compensationaction',
            name='action_type',
        ),
        migrations.RenameField(
            model_name='compensationaction',
            old_name='action_type_tmp',
            new_name='action_type',
        )
    ]