# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-03-26 19:52
from __future__ import unicode_literals

from django.conf import settings
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import django_fsm
import model_utils.fields


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Booking',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
                ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
                ('state', django_fsm.FSMField(choices=[('client_abort', 'отказ клиента'), ('for_payment', 'на оплату'), ('payed', 'оплачено клиентом'), ('waiting_for_approval', 'ждем подтверждения клиента'), ('waiting_for_parts', 'ждем запчасти'), ('without_repair', 'без ремонта'), ('working', 'в работе')], default='working', max_length=50, protected=True, verbose_name='статус')),
                ('client_name', models.CharField(help_text='Фамилия Имя Отчество', max_length=254, verbose_name='ФИО')),
                ('client_address', models.CharField(blank=True, max_length=254, verbose_name='адрес')),
                ('client_characteristic', models.CharField(blank=True, max_length=254, verbose_name='характеристика/внешний вид')),
                ('client_email', models.EmailField(blank=True, max_length=254, verbose_name='email')),
                ('client_phone', models.CharField(blank=True, max_length=254, verbose_name='телефон')),
                ('imei', models.CharField(blank=True, max_length=30, verbose_name='IMEI')),
                ('has_device', models.BooleanField(default=True, verbose_name='устройство')),
                ('has_battery', models.BooleanField(default=True, verbose_name='аккумулятор')),
                ('has_charger', models.BooleanField(default=False, verbose_name='зарядное устройство')),
                ('has_memory_card', models.BooleanField(default=False, verbose_name='карта памяти')),
                ('has_sim', models.BooleanField(default=False, verbose_name='SIM-карта')),
                ('has_bag_cover', models.BooleanField(default=False, verbose_name='сумка/чехол')),
                ('additional_kit', models.CharField(blank=True, max_length=254, verbose_name='дополнительно')),
                ('problem', models.TextField(verbose_name='неисправность')),
                ('note', models.CharField(blank=True, max_length=254, verbose_name='примечание')),
                ('estimated_date', models.DateField(verbose_name='предполагаемая дата готовности')),
                ('ready_date', models.DateTimeField(blank=True, editable=False, null=True, verbose_name='дата готовности')),
                ('close_date', models.DateTimeField(blank=True, editable=False, null=True, verbose_name='дата выдачи')),
                ('is_urgently', models.BooleanField(default=False, verbose_name='срочно')),
                ('estimated_cost', models.IntegerField(verbose_name='предполагаемая стоимость')),
                ('done_work', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True, verbose_name='выполненная работа')),
                ('gain', models.PositiveIntegerField(blank=True, default=0, null=True, verbose_name='полученные деньги')),
            ],
            options={
                'ordering': ['-pk'],
                'default_related_name': 'bookings',
                'verbose_name_plural': 'заявки',
                'verbose_name': 'заявка',
            },
        ),
        migrations.CreateModel(
            name='Brand',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(db_index=True, max_length=254, verbose_name='название')),
            ],
            options={
                'ordering': ['-name'],
                'verbose_name_plural': 'бренды',
                'verbose_name': 'бренд',
            },
        ),
        migrations.CreateModel(
            name='Client',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
                ('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
                ('name', models.CharField(max_length=254, verbose_name='имя')),
                ('surname', models.CharField(max_length=254, verbose_name='фамилия')),
                ('patronymic', models.CharField(blank=True, max_length=254, verbose_name='отчество')),
                ('address', models.CharField(blank=True, max_length=254, verbose_name='адрес')),
                ('characteristic', models.CharField(blank=True, max_length=254, verbose_name='характеристика')),
                ('email', models.EmailField(blank=True, max_length=254, verbose_name='email')),
                ('phone', models.CharField(blank=True, max_length=254, verbose_name='телефон')),
            ],
            options={
                'ordering': ['surname', 'name', 'patronymic'],
                'verbose_name_plural': 'клиенты',
                'verbose_name': 'клиент',
            },
        ),
        migrations.CreateModel(
            name='Guarantee',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(db_index=True, max_length=254, verbose_name='название')),
                ('day', models.PositiveSmallIntegerField(blank=True, null=True, verbose_name='дней')),
                ('month', models.PositiveSmallIntegerField(blank=True, null=True, verbose_name='месяцев')),
                ('year', models.PositiveSmallIntegerField(blank=True, null=True, verbose_name='лет')),
                ('order', models.PositiveIntegerField(default=0, verbose_name='порядок')),
            ],
            options={
                'ordering': ['order'],
                'verbose_name_plural': 'гарантии',
                'verbose_name': 'гарантия',
            },
        ),
        migrations.CreateModel(
            name='Job',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(db_index=True, max_length=254, verbose_name='наименование работы')),
                ('price', models.IntegerField(default=0, verbose_name='цена')),
            ],
            options={
                'ordering': ['title'],
                'verbose_name_plural': 'работы',
                'verbose_name': 'работа',
            },
        ),
        migrations.CreateModel(
            name='Model',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(db_index=True, max_length=254, verbose_name='название')),
                ('brand', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='crm.Brand', verbose_name='бренд')),
            ],
            options={
                'ordering': ['-name'],
                'verbose_name_plural': 'модели',
                'verbose_name': 'модель',
            },
        ),
        migrations.CreateModel(
            name='SparePart',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(db_index=True, max_length=254, verbose_name='название')),
                ('purchase_price', models.PositiveIntegerField(default=0, verbose_name='цена закупки')),
                ('retail_price', models.PositiveIntegerField(default=0, verbose_name='цена розницы')),
                ('brand', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='spare_parts', to='crm.Brand', verbose_name='бренд')),
                ('model', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='spare_parts', to='crm.Model', verbose_name='модель')),
            ],
            options={
                'ordering': ['title'],
                'default_related_name': 'spare_parts',
                'verbose_name_plural': 'запчасти',
                'verbose_name': 'запчасть',
            },
        ),
        migrations.CreateModel(
            name='SparePartCount',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(db_index=True, max_length=254, verbose_name='название')),
                ('purchase_price', models.PositiveIntegerField(default=0, verbose_name='цена закупки')),
                ('retail_price', models.PositiveIntegerField(default=0, verbose_name='цена розницы')),
                ('booking', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='spare_part_counts', to='crm.Booking', verbose_name='заявка')),
                ('brand', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='spare_part_counts', to='crm.Brand', verbose_name='бренд')),
                ('model', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='spare_part_counts', to='crm.Model', verbose_name='модель')),
                ('spare_part', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='spare_part_counts', to='crm.SparePart', verbose_name='запчасть')),
            ],
            options={
                'default_related_name': 'spare_part_counts',
                'verbose_name_plural': 'колличества запчастей',
                'verbose_name': 'колличество запчастей',
            },
        ),
        migrations.AddField(
            model_name='booking',
            name='brand',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='bookings', to='crm.Brand', verbose_name='бренд'),
        ),
        migrations.AddField(
            model_name='booking',
            name='client',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='bookings', to='crm.Client', verbose_name='клиент'),
        ),
        migrations.AddField(
            model_name='booking',
            name='guarantee',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='bookings', to='crm.Guarantee', verbose_name='гарантия'),
        ),
        migrations.AddField(
            model_name='booking',
            name='master',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='bookings', to=settings.AUTH_USER_MODEL, verbose_name='мастер'),
        ),
        migrations.AddField(
            model_name='booking',
            name='model',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='bookings', to='crm.Model', verbose_name='модель'),
        ),
        migrations.AddField(
            model_name='booking',
            name='spare_parts',
            field=models.ManyToManyField(related_name='bookings', through='crm.SparePartCount', to='crm.SparePart', verbose_name='запчасти'),
        ),
    ]
