# Generated by Django 4.2.28 on 2026-02-24 10:35

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('inventory', '0002_purchaseorder_supplier_purchaseorderitem_and_more'),
    ]

    operations = [
        migrations.CreateModel(
            name='Asset',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=255)),
                ('code', models.CharField(max_length=80, unique=True)),
                ('category', models.CharField(blank=True, max_length=100)),
                ('serial_number', models.CharField(blank=True, max_length=120)),
                ('purchase_date', models.DateField(blank=True, null=True)),
                ('purchase_cost', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('useful_life_years', models.PositiveIntegerField(default=5)),
                ('salvage_value', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('status', models.CharField(choices=[('active', 'Active'), ('maintenance', 'Maintenance'), ('retired', 'Retired'), ('lost', 'Lost')], default='active', max_length=20)),
                ('note', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ('name',),
            },
        ),
        migrations.CreateModel(
            name='ProductBatch',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('batch_number', models.CharField(max_length=100)),
                ('expiry_date', models.DateField(blank=True, null=True)),
                ('quantity', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('unit_cost', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('received_date', models.DateField(default=django.utils.timezone.now)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ('expiry_date', 'batch_number'),
            },
        ),
        migrations.CreateModel(
            name='ProductSerial',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('serial_number', models.CharField(max_length=150, unique=True)),
                ('status', models.CharField(choices=[('in_stock', 'In Stock'), ('sold', 'Sold'), ('damaged', 'Damaged'), ('returned', 'Returned')], default='in_stock', max_length=20)),
                ('note', models.CharField(blank=True, max_length=255)),
                ('received_date', models.DateField(default=django.utils.timezone.now)),
                ('sold_date', models.DateField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('batch', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='serials', to='inventory.productbatch')),
            ],
        ),
        migrations.CreateModel(
            name='PurchaseReturn',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('reference', models.CharField(max_length=50, unique=True)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('processed', 'Processed'), ('cancelled', 'Cancelled')], default='draft', max_length=20)),
                ('reason', models.TextField(blank=True)),
                ('date', models.DateField(default=django.utils.timezone.now)),
                ('processed_date', models.DateField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='purchase_returns_created', to=settings.AUTH_USER_MODEL)),
                ('processed_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='purchase_returns_processed', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ('-date', '-created_at'),
            },
        ),
        migrations.CreateModel(
            name='StockLocation',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=120, unique=True)),
                ('code', models.CharField(blank=True, max_length=20, unique=True)),
                ('description', models.TextField(blank=True)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ('name',),
            },
        ),
        migrations.CreateModel(
            name='StockTransfer',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('reference', models.CharField(max_length=50, unique=True)),
                ('status', models.CharField(choices=[('requested', 'Requested'), ('approved', 'Approved'), ('rejected', 'Rejected'), ('completed', 'Completed')], default='requested', max_length=20)),
                ('note', models.TextField(blank=True)),
                ('requested_at', models.DateTimeField(auto_now_add=True)),
                ('approved_at', models.DateTimeField(blank=True, null=True)),
                ('completed_at', models.DateTimeField(blank=True, null=True)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='approved_transfers', to=settings.AUTH_USER_MODEL)),
                ('from_location', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='outgoing_transfers', to='inventory.stocklocation')),
                ('requested_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='requested_transfers', to=settings.AUTH_USER_MODEL)),
                ('to_location', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='incoming_transfers', to='inventory.stocklocation')),
            ],
            options={
                'ordering': ('-requested_at',),
            },
        ),
        migrations.AddField(
            model_name='product',
            name='barcode',
            field=models.CharField(blank=True, db_index=True, max_length=100),
        ),
        migrations.AddField(
            model_name='product',
            name='image',
            field=models.ImageField(blank=True, null=True, upload_to='products/'),
        ),
        migrations.AddField(
            model_name='product',
            name='track_expiry',
            field=models.BooleanField(default=False),
        ),
        migrations.AddField(
            model_name='product',
            name='track_serial',
            field=models.BooleanField(default=False),
        ),
        migrations.AddField(
            model_name='purchaseorder',
            name='amount_paid',
            field=models.DecimalField(decimal_places=2, default=0, max_digits=15),
        ),
        migrations.AddField(
            model_name='purchaseorder',
            name='due_date',
            field=models.DateField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name='purchaseorder',
            name='supplier_invoice_number',
            field=models.CharField(blank=True, max_length=100),
        ),
        migrations.AddField(
            model_name='stockmovement',
            name='approved_at',
            field=models.DateTimeField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name='stockmovement',
            name='approved_by',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='approved_stock_movements', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='stockmovement',
            name='is_approved',
            field=models.BooleanField(default=True),
        ),
        migrations.AlterField(
            model_name='stockmovement',
            name='movement_type',
            field=models.CharField(choices=[('stock_in', 'Stock In'), ('stock_out', 'Stock Out'), ('sale', 'Sale'), ('adjustment', 'Adjustment'), ('return', 'Return'), ('transfer_out', 'Transfer Out'), ('transfer_in', 'Transfer In'), ('expired', 'Expired'), ('damaged', 'Damaged'), ('lost', 'Lost')], max_length=20),
        ),
        migrations.CreateModel(
            name='StockTransferItem',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantity', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('batch', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='transfer_items', to='inventory.productbatch')),
                ('product', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='transfer_items', to='inventory.product')),
                ('serial', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='transfer_items', to='inventory.productserial')),
                ('transfer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='inventory.stocktransfer')),
            ],
        ),
        migrations.CreateModel(
            name='StockAdjustmentRequest',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantity', models.DecimalField(decimal_places=2, max_digits=15)),
                ('reason', models.CharField(choices=[('damaged', 'Damaged'), ('lost', 'Lost'), ('expired', 'Expired'), ('correction', 'Correction')], max_length=20)),
                ('note', models.TextField(blank=True)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('approved', 'Approved'), ('rejected', 'Rejected')], default='pending', max_length=20)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('approved_at', models.DateTimeField(blank=True, null=True)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='approved_stock_adjustments', to=settings.AUTH_USER_MODEL)),
                ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='adjustment_requests', to='inventory.stocklocation')),
                ('product', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='adjustment_requests', to='inventory.product')),
                ('requested_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='stock_adjustment_requests', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ('-created_at',),
            },
        ),
        migrations.CreateModel(
            name='PurchaseReturnItem',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantity', models.DecimalField(decimal_places=2, max_digits=15)),
                ('unit_cost', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('product', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='inventory.product')),
                ('purchase_return', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='inventory.purchasereturn')),
            ],
        ),
        migrations.AddField(
            model_name='purchasereturn',
            name='purchase_order',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='returns', to='inventory.purchaseorder'),
        ),
        migrations.AddField(
            model_name='productserial',
            name='location',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='serials', to='inventory.stocklocation'),
        ),
        migrations.AddField(
            model_name='productserial',
            name='product',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='serials', to='inventory.product'),
        ),
        migrations.AddField(
            model_name='productbatch',
            name='location',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='batches', to='inventory.stocklocation'),
        ),
        migrations.AddField(
            model_name='productbatch',
            name='product',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='batches', to='inventory.product'),
        ),
        migrations.CreateModel(
            name='AssetMaintenance',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('description', models.CharField(max_length=255)),
                ('cost', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('service_date', models.DateField(default=django.utils.timezone.now)),
                ('next_due_date', models.DateField(blank=True, null=True)),
                ('performed_by', models.CharField(blank=True, max_length=255)),
                ('note', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('asset', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='maintenance_logs', to='inventory.asset')),
            ],
            options={
                'ordering': ('-service_date',),
            },
        ),
        migrations.CreateModel(
            name='AssetAssignment',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('assigned_date', models.DateField(default=django.utils.timezone.now)),
                ('returned_date', models.DateField(blank=True, null=True)),
                ('note', models.TextField(blank=True)),
                ('asset', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='assignments', to='inventory.asset')),
                ('assigned_to', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='asset_assignments', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ('-assigned_date',),
            },
        ),
        migrations.AddField(
            model_name='asset',
            name='location',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assets', to='inventory.stocklocation'),
        ),
        migrations.AddField(
            model_name='stockmovement',
            name='batch',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='movements', to='inventory.productbatch'),
        ),
        migrations.AddField(
            model_name='stockmovement',
            name='location',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='movements', to='inventory.stocklocation'),
        ),
        migrations.AddField(
            model_name='stockmovement',
            name='serial',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='movements', to='inventory.productserial'),
        ),
        migrations.CreateModel(
            name='ProductStock',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantity', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('location', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='product_stocks', to='inventory.stocklocation')),
                ('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='location_stocks', to='inventory.product')),
            ],
            options={
                'unique_together': {('product', 'location')},
            },
        ),
        migrations.AlterUniqueTogether(
            name='productbatch',
            unique_together={('product', 'location', 'batch_number')},
        ),
    ]
