# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-09-06 17:25
from __future__ import unicode_literals

from django.db import migrations

from codenerix_invoicing.models_sales import SalesAlbaran, SalesBasket, SalesInvoiceRectification, SalesOrder, SalesTicket, SalesTicketRectification
from codenerix_invoicing.models import BillingSeries


def run_migrate(apps, schema_editor):
    for model in [SalesAlbaran, SalesBasket, SalesInvoiceRectification, SalesOrder, SalesTicket, SalesTicketRectification]:
        i = 1
        for obj in model.objects.all().order_by("pk"):
            obj.code_counter = i
            obj.code = str(i)
            obj.billing_series_id = BillingSeries.objects.all().first().pk
            obj.save(force_save=True)
            i += 1


class Migration(migrations.Migration):

    dependencies = [
        ('codenerix_invoicing', '0042_auto_20170906_1636'),
    ]

    operations = [
        migrations.RunPython(run_migrate),
    ]
