# Generated by Django 6.0.4 on 2026-06-06 02:55

import apps.procurements.models
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('asset_management', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='GoodsReceipt',
            fields=[
                ('id', models.UUIDField(default=apps.procurements.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('receipt_number', models.CharField(max_length=50, unique=True)),
                ('received_date', models.DateField()),
                ('items', models.JSONField(default=list)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('received', 'Received'), ('partial', 'Partially Received'), ('rejected', 'Rejected')], default='pending', max_length=20)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('received_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'goods_receipts',
                'ordering': ['-received_date'],
            },
        ),
        migrations.CreateModel(
            name='Invoice',
            fields=[
                ('id', models.UUIDField(default=apps.procurements.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('invoice_number', models.CharField(max_length=50, unique=True)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('tax', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('total', models.DecimalField(decimal_places=2, max_digits=12)),
                ('due_date', models.DateField()),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('approved', 'Approved'), ('paid', 'Paid'), ('overdue', 'Overdue'), ('cancelled', 'Cancelled')], default='pending', max_length=20)),
                ('paid_at', models.DateTimeField(blank=True, null=True)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('goods_receipt', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoices', to='procurements.goodsreceipt')),
                ('vendor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='invoices', to='asset_management.vendor')),
            ],
            options={
                'db_table': 'invoices',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='Payment',
            fields=[
                ('id', models.UUIDField(default=apps.procurements.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('method', models.CharField(choices=[('bank_transfer', 'Bank Transfer'), ('cash', 'Cash'), ('check', 'Check'), ('card', 'Card')], max_length=20)),
                ('reference', models.CharField(blank=True, max_length=100)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('completed', 'Completed'), ('failed', 'Failed')], default='pending', max_length=20)),
                ('paid_at', models.DateTimeField(blank=True, null=True)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('invoice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payments', to='procurements.invoice')),
            ],
            options={
                'db_table': 'payments',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='ProcurementContract',
            fields=[
                ('id', models.UUIDField(default=apps.procurements.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('title', models.CharField(max_length=255)),
                ('contract_number', models.CharField(max_length=100, unique=True)),
                ('value', models.DecimalField(decimal_places=2, max_digits=12)),
                ('start_date', models.DateField()),
                ('end_date', models.DateField(blank=True, null=True)),
                ('status', models.CharField(choices=[('active', 'Active'), ('expired', 'Expired'), ('terminated', 'Terminated')], default='active', max_length=20)),
                ('document', models.FileField(blank=True, null=True, upload_to='procurement_contracts/')),
                ('terms', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('vendor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='procurement_contracts', to='asset_management.vendor')),
            ],
            options={
                'db_table': 'procurement_contracts',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='PurchaseOrder',
            fields=[
                ('id', models.UUIDField(default=apps.procurements.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('order_number', models.CharField(max_length=50, unique=True)),
                ('items', models.JSONField(default=list)),
                ('subtotal', models.DecimalField(decimal_places=2, max_digits=12)),
                ('tax', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('total', models.DecimalField(decimal_places=2, max_digits=12)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('sent', 'Sent'), ('acknowledged', 'Acknowledged'), ('fulfilled', 'Fulfilled'), ('cancelled', 'Cancelled')], default='draft', max_length=20)),
                ('expected_delivery', models.DateField(blank=True, null=True)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('vendor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='purchase_orders', to='asset_management.vendor')),
            ],
            options={
                'db_table': 'purchase_orders',
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddField(
            model_name='invoice',
            name='purchase_order',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoices', to='procurements.purchaseorder'),
        ),
        migrations.AddField(
            model_name='goodsreceipt',
            name='purchase_order',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='goods_receipts', to='procurements.purchaseorder'),
        ),
        migrations.CreateModel(
            name='Requisition',
            fields=[
                ('id', models.UUIDField(default=apps.procurements.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('number', models.CharField(blank=True, max_length=40, unique=True)),
                ('title', models.CharField(max_length=255)),
                ('description', models.TextField(blank=True)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('pending', 'Pending'), ('approved', 'Approved'), ('rejected', 'Rejected'), ('fulfilled', 'Fulfilled')], default='draft', max_length=20)),
                ('items', models.JSONField(default=list)),
                ('total_amount', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('requested_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='requisitions', to=settings.AUTH_USER_MODEL)),
                ('vendor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='requisitions', to='asset_management.vendor')),
            ],
            options={
                'db_table': 'requisitions',
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddField(
            model_name='purchaseorder',
            name='requisition',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='purchase_orders', to='procurements.requisition'),
        ),
        migrations.CreateModel(
            name='Approval',
            fields=[
                ('id', models.UUIDField(default=apps.procurements.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('approved', 'Approved'), ('rejected', 'Rejected')], default='pending', max_length=20)),
                ('comment', models.TextField(blank=True)),
                ('resolved_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('approver', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='requisition_approvals', to=settings.AUTH_USER_MODEL)),
                ('requisition', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='approvals', to='procurements.requisition')),
            ],
            options={
                'db_table': 'requisition_approvals',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='RFQRFP',
            fields=[
                ('id', models.UUIDField(default=apps.procurements.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('title', models.CharField(max_length=255)),
                ('rfq_rfp_type', models.CharField(choices=[('rfq', 'Request for Quote'), ('rfp', 'Request for Proposal')], max_length=10)),
                ('description', models.TextField()),
                ('requirements', models.TextField()),
                ('deadline', models.DateTimeField()),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('published', 'Published'), ('closed', 'Closed'), ('awarded', 'Awarded')], default='draft', max_length=20)),
                ('attachments', models.JSONField(default=list)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rfq_rfps', to=settings.AUTH_USER_MODEL)),
                ('vendor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='rfq_rfps', to='asset_management.vendor')),
            ],
            options={
                'db_table': 'rfq_rfps',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='RequisitionQuote',
            fields=[
                ('id', models.UUIDField(default=apps.procurements.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ('quoted_amount', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)),
                ('delivery_estimate', models.CharField(blank=True, max_length=100)),
                ('is_selected', models.BooleanField(default=False)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('requisition', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='quotes', to='procurements.requisition')),
                ('vendor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='requisition_quotes', to='asset_management.vendor')),
            ],
            options={
                'db_table': 'requisition_quotes',
                'ordering': ['-is_selected', 'quoted_amount'],
                'constraints': [models.UniqueConstraint(fields=('requisition', 'vendor'), name='uniq_requisition_vendor_quote')],
            },
        ),
    ]
