# -*- coding: utf-8 -*-
# Generated by Django 1.11.13 on 2018-08-30 14:49
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('support', '0024_offeringplan'),
    ]

    def migrate_config(apps, schema_editor):
        from waldur_mastermind.common.mixins import UnitPriceMixin

        OfferingTemplate = apps.get_model('support', 'OfferingTemplate')
        OfferingPlan = apps.get_model('support', 'OfferingPlan')

        for template in OfferingTemplate.objects.all():
            OfferingPlan.objects.create(
                template=template,
                name='Default',
                product_code=template.config.get('product_code', ''),
                article_code=template.config.get('article_code', ''),
                unit_price=template.config.get('price', 0),
                unit=template.config.get('unit', UnitPriceMixin.Units.PER_MONTH),
            )

    operations = [
        migrations.RunPython(migrate_config, elidable=True),
    ]
