# -*- coding: utf-8 -*-
# Generated by Django 1.11.21 on 2019-09-09 13:20
from __future__ import unicode_literals

from decimal import Decimal
import django.contrib.postgres.fields.jsonb
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import waldur_core.core.fields
import waldur_mastermind.invoices.models
import waldur_mastermind.invoices.utils


class Migration(migrations.Migration):

    replaces = [(b'invoices', '0001_initial'), (b'invoices', '0002_invoice_additional_details'), (b'invoices', '0003_paymentdetails_default_tax_percent'), (b'invoices', '0004_paymentdetails_uuid'), (b'invoices', '0005_add_company_type'), (b'invoices', '0006_add_daily_price'), (b'invoices', '0007_item_remove_price'), (b'invoices', '0008_offeringitem'), (b'invoices', '0009_quantize_prices'), (b'invoices', '0010_add_product_code'), (b'invoices', '0011_add_article_code'), (b'invoices', '0012_add_project_to_invoice_item'), (b'invoices', '0013_set_projects_for_invoice_items'), (b'invoices', '0014_add_accounting_start_date'), (b'invoices', '0015_add_unit_price'), (b'invoices', '0016_remove_daily_price'), (b'invoices', '0017_genericinvoiceitem'), (b'invoices', '0018_genericinvoiceitem_quantity'), (b'invoices', '0019_mark_payments_details_fields'), (b'invoices', '0020_migrate_payment_details_data'), (b'invoices', '0021_remove_pending_offering_item'), (b'invoices', '0022_remove_payment_details'), (b'invoices', '0023_invoice_current_cost'), (b'invoices', '0024_immutable_default_json'), (b'invoices', '0025_servicedowntime'), (b'invoices', '0026_invoice__file'), (b'invoices', '0027_migrate_items'), (b'invoices', '0028_delete_offering_and_openstack_item'), (b'invoices', '0029_migrate_invoice_item_name'), (b'invoices', '0030_json_details_on_genericinvoiceitem')]

    initial = True

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        ('support', '0010_add_unit_price'),
        ('packages', '0002_openstack_packages'),
        ('packages', '0013_packagetemplate_article_code'),
        ('structure', '0054_payment_details'),
        ('structure', '0037_remove_customer_billing_backend_id'),
        ('support', '0006_offering'),
        ('packages', '0014_unique_package_tenant'),
        ('support', '0011_remove_price'),
        ('support', '0009_offering_article_code'),
        ('structure', '0052_customer_subnets'),
    ]

    operations = [
        migrations.CreateModel(
            name='Invoice',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('uuid', waldur_core.core.fields.UUIDField()),
                ('month', models.PositiveSmallIntegerField(default=waldur_mastermind.invoices.utils.get_current_month, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(12)])),
                ('year', models.PositiveSmallIntegerField(default=waldur_mastermind.invoices.utils.get_current_year)),
                ('state', models.CharField(choices=[('pending', 'Pending'), ('created', 'Created'), ('paid', 'Paid'), ('canceled', 'Canceled')], default='pending', max_length=30)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='structure.Customer', verbose_name='organization')),
                ('invoice_date', models.DateField(blank=True, help_text='Date then invoice moved from state pending to created.', null=True)),
                ('tax_percent', models.DecimalField(decimal_places=2, default=0, max_digits=4, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(100)])),
            ],
        ),
        migrations.AlterUniqueTogether(
            name='invoice',
            unique_together=set([('customer', 'month', 'year')]),
        ),
        migrations.CreateModel(
            name='GenericInvoiceItem',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('unit_price', models.DecimalField(decimal_places=7, default=0, max_digits=22, validators=[django.core.validators.MinValueValidator(Decimal('0'))])),
                ('unit', models.CharField(choices=[(b'month', 'Per month'), (b'half_month', 'Per half month'), (b'day', 'Per day'), (b'hour', 'Per hour'), (b'quantity', 'Quantity')], default=b'day', max_length=30)),
                ('product_code', models.CharField(blank=True, max_length=30)),
                ('article_code', models.CharField(blank=True, max_length=30)),
                ('start', models.DateTimeField(default=waldur_mastermind.invoices.utils.get_current_month_start, help_text='Date and time when item usage has started.')),
                ('end', models.DateTimeField(default=waldur_mastermind.invoices.utils.get_current_month_end, help_text='Date and time when item usage has ended.')),
                ('project_name', models.CharField(blank=True, max_length=150)),
                ('project_uuid', models.CharField(blank=True, max_length=32)),
                ('object_id', models.PositiveIntegerField(null=True)),
                ('details', django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict, help_text='Stores data about scope')),
                ('content_type', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='contenttypes.ContentType')),
                ('invoice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='generic_items', to='invoices.Invoice')),
                ('project', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='structure.Project')),
                ('quantity', models.PositiveIntegerField(default=0)),
            ],
            options={
                'abstract': False,
            },
        ),
        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.CreateModel(
            name='ServiceDowntime',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('start', models.DateTimeField(default=waldur_mastermind.invoices.models.get_default_downtime_start, help_text='Date and time when downtime has started.')),
                ('end', models.DateTimeField(default=django.utils.timezone.now, help_text='Date and time when downtime has ended.')),
                ('package', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='packages.OpenStackPackage')),
            ],
        ),
        migrations.AddField(
            model_name='invoice',
            name='_file',
            field=models.TextField(blank=True, editable=False),
        ),
    ]
