# Generated by Django 3.0.7 on 2020-06-18 17:09

from django.db import migrations, transaction


class Migration(migrations.Migration):

    def copy_data(apps, schema_editor):
        from kaf_pas.sales.models.precent_materials import Precent_materials
        from kaf_pas.sales.models.demand_materials import Demand_materials

        with transaction.atomic():
            for precent_material in Precent_materials.objects.filter(id__in=[demand.precent_material.id for demand in Demand_materials.objects.all()]):
                demand_material = Demand_materials.objects.get(precent_material=precent_material)
                demand_material.material = precent_material.material
                demand_material.material_askon = precent_material.material_askon
                demand_material.qty = precent_material.qty
                demand_material.edizm = precent_material.edizm
                demand_material.save()

    dependencies = [
        ('sales', '0130_auto_20200618_1702'),
    ]

    operations = [
        migrations.RunPython(copy_data)
    ]
