from __future__ import unicode_literals

from django.db import migrations, models


def migrate_data(apps, schema_editor):
    Invoice = apps.get_model('invoices', 'Invoice')

    for invoice in Invoice.objects.all():
        invoice.update_current_cost()


class Migration(migrations.Migration):

    dependencies = [
        ('invoices', '0022_remove_payment_details'),
    ]

    operations = [
        migrations.AddField(
            model_name='invoice',
            name='current_cost',
            field=models.DecimalField(decimal_places=2, default=0, editable=False, help_text='Cached value for current cost.', max_digits=10),
        ),
        migrations.RunPython(migrate_data, reverse_code=migrations.RunPython.noop),
    ]

from __future__ import unicode_literals

from django.db import migrations, models


def migrate_data(apps, schema_editor):
    from waldur_mastermind.invoices.models import Invoice

    for invoice in Invoice.objects.all():
        invoice.update_current_cost()


class Migration(migrations.Migration):

    dependencies = [
        ('invoices', '0022_remove_payment_details'),
    ]

    operations = [
        migrations.AddField(
            model_name='invoice',
            name='current_cost',
            field=models.DecimalField(decimal_places=2, default=0, editable=False, help_text='Cached value for current cost.', max_digits=10),
        ),
        migrations.RunPython(migrate_data, reverse_code=migrations.RunPython.noop),
    ]

Fix database migration for invoices application.
Fix database migration for invoices application.

  from __future__ import unicode_literals
  
  from django.db import migrations, models
  
  
  def migrate_data(apps, schema_editor):
-     Invoice = apps.get_model('invoices', 'Invoice')
+     from waldur_mastermind.invoices.models import Invoice
  
      for invoice in Invoice.objects.all():
          invoice.update_current_cost()
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('invoices', '0022_remove_payment_details'),
      ]
  
      operations = [
          migrations.AddField(
              model_name='invoice',
              name='current_cost',
              field=models.DecimalField(decimal_places=2, default=0, editable=False, help_text='Cached value for current cost.', max_digits=10),
          ),
          migrations.RunPython(migrate_data, reverse_code=migrations.RunPython.noop),
      ]
  
Fix database migration for invoices application.
## Code Before:
from __future__ import unicode_literals

from django.db import migrations, models


def migrate_data(apps, schema_editor):
    Invoice = apps.get_model('invoices', 'Invoice')

    for invoice in Invoice.objects.all():
        invoice.update_current_cost()


class Migration(migrations.Migration):

    dependencies = [
        ('invoices', '0022_remove_payment_details'),
    ]

    operations = [
        migrations.AddField(
            model_name='invoice',
            name='current_cost',
            field=models.DecimalField(decimal_places=2, default=0, editable=False, help_text='Cached value for current cost.', max_digits=10),
        ),
        migrations.RunPython(migrate_data, reverse_code=migrations.RunPython.noop),
    ]

## Instruction:
Fix database migration for invoices application.
## Code After:
from __future__ import unicode_literals

from django.db import migrations, models


def migrate_data(apps, schema_editor):
    from waldur_mastermind.invoices.models import Invoice

    for invoice in Invoice.objects.all():
        invoice.update_current_cost()


class Migration(migrations.Migration):

    dependencies = [
        ('invoices', '0022_remove_payment_details'),
    ]

    operations = [
        migrations.AddField(
            model_name='invoice',
            name='current_cost',
            field=models.DecimalField(decimal_places=2, default=0, editable=False, help_text='Cached value for current cost.', max_digits=10),
        ),
        migrations.RunPython(migrate_data, reverse_code=migrations.RunPython.noop),
    ]
