# Generated by Django 6.0.2 on 2026-02-22 13:39

import django.db.models.deletion
import django.db.models.expressions
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Footprint',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=64)),
            ],
        ),
        migrations.CreateModel(
            name='Inventory',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=64)),
            ],
            options={
                'verbose_name_plural': 'Inventories',
            },
        ),
        migrations.CreateModel(
            name='Project',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=64)),
                ('git_server', models.PositiveSmallIntegerField(choices=[(0, 'Unknown'), (1, 'Github')], default=1)),
                ('git_user', models.CharField(max_length=64, null=True)),
                ('git_repo', models.CharField(max_length=64, null=True)),
            ],
        ),
        migrations.CreateModel(
            name='ProjectBuild',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantity', models.SmallIntegerField()),
                ('created', models.DateTimeField(default=django.utils.timezone.now)),
                ('cleared', models.DateTimeField(blank=True, null=True)),
                ('completed', models.DateTimeField(blank=True, null=True)),
            ],
        ),
        migrations.CreateModel(
            name='Vendor',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=64)),
                ('base_url', models.URLField(help_text='sans trailing slash plz')),
            ],
        ),
        migrations.CreateModel(
            name='Package',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('technology', models.PositiveSmallIntegerField(choices=[(0, 'Through Hole'), (1, 'Surface Mount'), (2, 'Unknown')], default=2)),
                ('name', models.CharField(help_text='e.g. 0805, or TO-92W', max_length=32)),
                ('footprints', models.ManyToManyField(blank=True, to='django_ctb.footprint')),
            ],
        ),
        migrations.CreateModel(
            name='Part',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=64)),
                ('description', models.CharField(blank=True, max_length=256, null=True)),
                ('value', models.CharField(blank=True, help_text="Value as found on BOM e.g. '10K', '22u'", max_length=32, null=True)),
                ('tolerance', models.SmallIntegerField(blank=True, help_text='as percentage', null=True)),
                ('loading_limit', models.CharField(blank=True, max_length=16, null=True)),
                ('unit', models.PositiveSmallIntegerField(choices=[(0, 'None'), (1, 'Ohm'), (2, 'Farad'), (3, 'Henry'), (4, 'Volt'), (5, 'Ampere')], default=0)),
                ('symbol', models.CharField(blank=True, help_text='What prefix might this part have on a circuit schematic?', max_length=4, null=True)),
                ('_is_scraped', models.BooleanField(default=False)),
                ('equivalent_to', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='equivalents', to='django_ctb.part')),
                ('package', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='django_ctb.package')),
            ],
        ),
        migrations.CreateModel(
            name='InventoryLine',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(default=django.utils.timezone.now)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('quantity', models.IntegerField(default=0, help_text='quantity on hand (unused reservations are removed from this number)')),
                ('is_deprioritized', models.BooleanField(default=False)),
                ('inventory', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='django_ctb.inventory')),
                ('part', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='inventory_lines', to='django_ctb.part')),
            ],
        ),
        migrations.CreateModel(
            name='ImplicitProjectPart',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantity', models.SmallIntegerField(default=1)),
                ('for_package', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='django_ctb.package')),
                ('part', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='django_ctb.part')),
            ],
        ),
        migrations.CreateModel(
            name='ProjectBuildPartShortage',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantity', models.SmallIntegerField()),
                ('created', models.DateTimeField(default=django.utils.timezone.now)),
                ('part', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='django_ctb.part')),
                ('project_build', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='shortfalls', to='django_ctb.projectbuild')),
            ],
        ),
        migrations.CreateModel(
            name='ProjectPart',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('missing_part_description', models.CharField(blank=True, max_length=256, null=True)),
                ('line_number', models.SmallIntegerField()),
                ('quantity', models.SmallIntegerField()),
                ('is_implicit', models.BooleanField(default=False)),
                ('is_optional', models.BooleanField(default=False)),
                ('part', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='project_parts', to='django_ctb.part')),
                ('substitute_part', models.ForeignKey(blank=True, help_text='When set, the substitute part will be used instead of the actual part', null=True, on_delete=django.db.models.deletion.PROTECT, related_name='substitute_project_part', to='django_ctb.part')),
            ],
        ),
        migrations.CreateModel(
            name='ProjectBuildPartReservation',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(default=django.utils.timezone.now)),
                ('utilized', models.DateTimeField(blank=True, null=True)),
                ('part', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='reservations', to='django_ctb.part')),
                ('project_build', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='part_reservations', to='django_ctb.projectbuild')),
                ('project_parts', models.ManyToManyField(related_name='part_reservations', to='django_ctb.projectpart')),
            ],
        ),
        migrations.AddField(
            model_name='projectbuild',
            name='excluded_project_parts',
            field=models.ManyToManyField(blank=True, to='django_ctb.projectpart'),
        ),
        migrations.CreateModel(
            name='ProjectPartFootprintRef',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('footprint_ref', models.CharField(max_length=8)),
                ('project_part', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='footprint_refs', to='django_ctb.projectpart')),
            ],
        ),
        migrations.CreateModel(
            name='ProjectVersion',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('revision', models.IntegerField(default=0)),
                ('commit_ref', models.CharField(help_text='Commit or tag representing the version', max_length=64)),
                ('bom_path', models.CharField(max_length=100)),
                ('pcb_url', models.URLField(blank=True, help_text='OSH park link to pcb', null=True)),
                ('pcb_cost', models.DecimalField(blank=True, decimal_places=2, help_text='for lot of 3', max_digits=6, null=True)),
                ('synced', models.DateTimeField(blank=True, null=True)),
                ('last_synced_commit', models.CharField(blank=True, max_length=64, null=True)),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='django_ctb.project')),
            ],
        ),
        migrations.AddField(
            model_name='projectpart',
            name='project_version',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='project_parts', to='django_ctb.projectversion'),
        ),
        migrations.AddField(
            model_name='projectbuild',
            name='project_version',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='django_ctb.projectversion'),
        ),
        migrations.CreateModel(
            name='VendorOrder',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('order_number', models.CharField(blank=True, max_length=128, null=True)),
                ('created', models.DateTimeField(default=django.utils.timezone.now)),
                ('placed', models.DateTimeField(blank=True, null=True)),
                ('fulfilled', models.DateTimeField(blank=True, null=True)),
                ('vendor', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='orders', to='django_ctb.vendor')),
            ],
        ),
        migrations.CreateModel(
            name='VendorOrderLine',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantity', models.PositiveIntegerField()),
                ('cost', models.DecimalField(decimal_places=4, help_text='per unit', max_digits=8)),
                ('for_inventory', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='django_ctb.inventory')),
                ('vendor_order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='django_ctb.vendororder')),
            ],
        ),
        migrations.CreateModel(
            name='InventoryAction',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('delta', models.IntegerField()),
                ('created', models.DateTimeField(default=django.utils.timezone.now)),
                ('inventory_line', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='inventory_actions', to='django_ctb.inventoryline')),
                ('reservation', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='inventory_actions', to='django_ctb.projectbuildpartreservation')),
                ('order_line', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='django_ctb.vendororderline')),
            ],
        ),
        migrations.CreateModel(
            name='VendorPart',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('item_number', models.CharField(help_text='how the vendor identifies the part', max_length=64)),
                ('cost', models.DecimalField(blank=True, decimal_places=4, help_text='Cost per unit when purchased at given volume', max_digits=8, null=True)),
                ('volume', models.PositiveIntegerField(blank=True, help_text='Must purchase this many to get cost', null=True)),
                ('url_path', models.CharField(blank=True, help_text='includes the leading slash!', max_length=128, null=True)),
                ('lot_cost', models.GeneratedField(db_persist=False, expression=django.db.models.expressions.CombinedExpression(models.F('cost'), '*', models.F('volume')), output_field=models.DecimalField(decimal_places=4, max_digits=8))),
                ('part', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='part_vendors', to='django_ctb.part')),
                ('vendor', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='vendor_parts', to='django_ctb.vendor')),
            ],
            options={
                'ordering': ('vendor__name', 'item_number'),
            },
        ),
        migrations.AddField(
            model_name='vendororderline',
            name='vendor_part',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='lines', to='django_ctb.vendorpart'),
        ),
        migrations.AddField(
            model_name='part',
            name='vendors',
            field=models.ManyToManyField(related_name='parts', through='django_ctb.VendorPart', to='django_ctb.vendor'),
        ),
    ]
