# Generated by Django 3.0.2 on 2020-02-03 03:08

import checkout.validators
from django.conf import settings
import django.contrib.postgres.fields.jsonb
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import djmoney.models.fields
import model_utils.fields


class Migration(migrations.Migration):

    initial = True

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

    operations = [
        migrations.CreateModel(
            name='Cancellation',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('modified_at', models.DateTimeField(auto_now=True)),
                ('reason', models.TextField()),
            ],
        ),
        migrations.CreateModel(
            name='Customer',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('identity_document', models.CharField(max_length=50)),
                ('company', models.CharField(blank=True, max_length=100, null=True)),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='DiscountCode',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(max_length=50)),
                ('description', models.TextField()),
                ('type', models.CharField(choices=[('ITEM', 'Item'), ('ORDER', 'Orden')], max_length=10)),
                ('percentage', models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MaxValueValidator(100)])),
                ('fixed_value', models.PositiveIntegerField(blank=True, null=True)),
            ],
        ),
        migrations.CreateModel(
            name='Item',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=200)),
                ('type', models.CharField(choices=[('PASS', 'Pase'), ('ADDON', 'Addon')], max_length=10)),
                ('price_currency', djmoney.models.fields.CurrencyField(choices=[('ARS', 'Argentine Peso')], default='ARS', editable=False, max_length=3)),
                ('price', djmoney.models.fields.MoneyField(decimal_places=2, default_currency='ARS', max_digits=7)),
                ('stock', models.PositiveIntegerField(default=0)),
                ('cancellable', models.BooleanField(default=True)),
            ],
        ),
        migrations.CreateModel(
            name='ItemOption',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=50)),
                ('type', models.CharField(choices=[('TEXT', 'Texto'), ('EMAIL', 'Email'), ('COLOR', 'Color')], max_length=10)),
                ('possible_values', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True, validators=[checkout.validators.validate_list])),
                ('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='options', to='checkout.Item')),
            ],
        ),
        migrations.CreateModel(
            name='Order',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('modified_at', models.DateTimeField(auto_now=True)),
                ('notes', models.TextField()),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='orders', to='checkout.Customer')),
                ('discount_code', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to='checkout.DiscountCode')),
            ],
        ),
        migrations.CreateModel(
            name='OrderItem',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('amount', models.PositiveSmallIntegerField(default=1, validators=[django.core.validators.MinValueValidator(1)])),
                ('price_currency', djmoney.models.fields.CurrencyField(choices=[('ARS', 'Argentine Peso')], default='ARS', editable=False, max_length=3)),
                ('price', djmoney.models.fields.MoneyField(decimal_places=2, default_currency='ARS', max_digits=7)),
                ('fulfilled', models.BooleanField(default=False)),
                ('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='order_items', to='checkout.Item')),
                ('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='checkout.Order')),
            ],
        ),
        migrations.CreateModel(
            name='Refund',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('external_id', models.CharField(max_length=100)),
                ('status', model_utils.fields.StatusField(choices=[('CREATED', 'Creado'), ('COMPLETED', 'Completado')], default='CREATED', max_length=100, no_check_for_status=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('modified_at', models.DateTimeField(auto_now=True)),
                ('cancellation', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='checkout.Cancellation')),
            ],
        ),
        migrations.CreateModel(
            name='Payment',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('external_id', models.CharField(max_length=100)),
                ('status', model_utils.fields.StatusField(choices=[('CREATED', 'Creado'), ('IN_PROCESS', 'En proceso'), ('REJECTED', 'Rechazado'), ('APPROVED', 'Aprobado'), ('CANCELLED', 'Cancelado')], default='CREATED', max_length=100, no_check_for_status=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('modified_at', models.DateTimeField(auto_now=True)),
                ('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payments', to='checkout.Order')),
            ],
        ),
        migrations.CreateModel(
            name='OrderItemOption',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('value', django.contrib.postgres.fields.jsonb.JSONField(validators=[checkout.validators.validate_single_value])),
                ('item_option', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='checkout.ItemOption')),
                ('order_item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='options', to='checkout.OrderItem')),
            ],
        ),
        migrations.CreateModel(
            name='Invoice',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('number', models.PositiveIntegerField()),
                ('file', models.FileField(upload_to='invoices/')),
                ('order', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='checkout.Order')),
            ],
        ),
        migrations.CreateModel(
            name='DiscountCodeRestriction',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('type', models.CharField(choices=[('DATE', 'Fecha'), ('STOCK', 'Cantidad'), ('EMAIL', 'Email')], max_length=10)),
                ('value', django.contrib.postgres.fields.jsonb.JSONField(validators=[checkout.validators.validate_single_value])),
                ('discount_code', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='restrictions', to='checkout.DiscountCode')),
            ],
        ),
        migrations.AddField(
            model_name='discountcode',
            name='items',
            field=models.ManyToManyField(related_name='discount_codes', to='checkout.Item'),
        ),
        migrations.CreateModel(
            name='CreditNote',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('number', models.PositiveIntegerField()),
                ('file', models.FileField(upload_to='credit_notes/')),
                ('cancellation', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='checkout.Cancellation')),
            ],
        ),
        migrations.CreateModel(
            name='CancellationItem',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('cancellation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='checkout.Cancellation')),
                ('order_item', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='checkout.OrderItem')),
            ],
        ),
        migrations.AddField(
            model_name='cancellation',
            name='cancelled_items',
            field=models.ManyToManyField(related_name='cancellation', through='checkout.CancellationItem', to='checkout.OrderItem'),
        ),
        migrations.AddField(
            model_name='cancellation',
            name='order',
            field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='checkout.Order'),
        ),
    ]
