# Generated by Django 5.2.19 on 2026-11-29 09:32

import django.db.models.deletion
import uuid
from decimal import Decimal
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('accounting', '0006_accountingpolicy_default_valuation_method_and_more'),
        ('budgeting', '0001_initial'),
        ('inventory', '0001_initial'),
        ('projects', '0001_initial'),
        ('tenancy', '0002_company_multi_currency_enabled'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='PurchaseOrder',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('po_number', models.CharField(max_length=40)),
                ('po_date', models.DateField(db_index=True)),
                ('bs_date', models.CharField(blank=True, max_length=16)),
                ('order_kind', models.CharField(choices=[('STANDARD', 'Standard Purchase Order'), ('PROJECT', 'Project Material Order'), ('SERVICE', 'Service Order'), ('EQUIPMENT_RENTAL', 'Equipment Rental Order'), ('SUBCONTRACT', 'Subcontractor Work Order'), ('BLANKET', 'Blanket / Rate Agreement')], default='PROJECT', max_length=20)),
                ('payment_terms_days', models.PositiveSmallIntegerField(default=30)),
                ('subtotal_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('tax_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('total_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('justification', models.TextField(blank=True)),
                ('amendment_count', models.PositiveSmallIntegerField(default=0)),
                ('status', models.CharField(choices=[('DRAFT', 'Draft'), ('SUBMITTED', 'Submitted'), ('APPROVED', 'Approved & Committed'), ('PARTIAL', 'Partially Received / Billed'), ('CLOSED', 'Closed'), ('CANCELLED', 'Cancelled')], db_index=True, default='DRAFT', max_length=16)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='approved_pos', to=settings.AUTH_USER_MODEL)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='purchase_orders', to='tenancy.company')),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='created_pos', to=settings.AUTH_USER_MODEL)),
                ('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.project')),
                ('site', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.site')),
            ],
            options={
                'db_table': 'purchase_orders',
                'ordering': ['-po_date', '-created_at'],
            },
        ),
        migrations.CreateModel(
            name='PurchaseOrderLine',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('description', models.CharField(max_length=220)),
                ('unit', models.CharField(default='Units', max_length=24)),
                ('ordered_qty', models.DecimalField(decimal_places=3, max_digits=14)),
                ('received_qty', models.DecimalField(decimal_places=3, default=Decimal('0.000'), max_digits=14)),
                ('billed_qty', models.DecimalField(decimal_places=3, default=Decimal('0.000'), max_digits=14)),
                ('unit_rate', models.DecimalField(decimal_places=2, max_digits=14)),
                ('tax_rate', models.DecimalField(decimal_places=2, default=Decimal('13.00'), max_digits=5)),
                ('line_total', models.DecimalField(decimal_places=2, max_digits=18)),
                ('budget_line', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='budgeting.budgetline')),
                ('cost_code', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.costcode')),
                ('item', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='inventory.itemmaster')),
                ('purchase_order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='procurement.purchaseorder')),
            ],
            options={
                'db_table': 'purchase_order_lines',
            },
        ),
        migrations.CreateModel(
            name='PurchaseRequisition',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('requisition_no', models.CharField(max_length=40)),
                ('requisition_date', models.DateField()),
                ('bs_date', models.CharField(blank=True, max_length=16)),
                ('required_delivery_date', models.DateField()),
                ('priority', models.CharField(default='NORMAL', max_length=16)),
                ('budget_warning', models.CharField(blank=True, max_length=255)),
                ('status', models.CharField(choices=[('DRAFT', 'Draft'), ('DEPT_APPROVED', 'Department Approved'), ('BUDGET_CHECKED', 'Budget Validated'), ('APPROVED', 'Procurement Approved'), ('CONVERTED', 'Converted to RFQ / PO'), ('REJECTED', 'Rejected')], db_index=True, default='DRAFT', max_length=20)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='approved_prs', to=settings.AUTH_USER_MODEL)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='purchase_requisitions', to='tenancy.company')),
                ('department', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='accounting.department')),
                ('project', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='projects.project')),
                ('requested_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='requested_prs', to=settings.AUTH_USER_MODEL)),
                ('site', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.site')),
            ],
            options={
                'db_table': 'purchase_requisitions',
                'ordering': ['-requisition_date', '-created_at'],
                'unique_together': {('company', 'requisition_no')},
            },
        ),
        migrations.AddField(
            model_name='purchaseorder',
            name='requisition',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='procurement.purchaserequisition'),
        ),
        migrations.CreateModel(
            name='PurchaseRequisitionLine',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('description', models.CharField(max_length=220)),
                ('unit', models.CharField(default='Bags', max_length=24)),
                ('requested_qty', models.DecimalField(decimal_places=3, max_digits=14)),
                ('estimated_rate', models.DecimalField(decimal_places=2, max_digits=14)),
                ('estimated_total', models.DecimalField(decimal_places=2, max_digits=18)),
                ('budget_line', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='budgeting.budgetline')),
                ('cost_code', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.costcode')),
                ('item', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='inventory.itemmaster')),
                ('requisition', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='procurement.purchaserequisition')),
            ],
            options={
                'db_table': 'purchase_requisition_lines',
            },
        ),
        migrations.CreateModel(
            name='RFQ',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('rfq_no', models.CharField(max_length=40)),
                ('rfq_date', models.DateField()),
                ('deadline', models.DateField()),
                ('status', models.CharField(choices=[('OPEN', 'Open for Quotations'), ('EVALUATED', 'Quotations Evaluated'), ('AWARDED', 'Awarded to PO'), ('CLOSED', 'Closed')], default='OPEN', max_length=16)),
                ('notes', models.TextField(blank=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rfqs', to='tenancy.company')),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
                ('requisition', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='rfqs', to='procurement.purchaserequisition')),
            ],
            options={
                'db_table': 'rfqs',
                'ordering': ['-rfq_date'],
            },
        ),
        migrations.AddField(
            model_name='purchaseorder',
            name='rfq',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='procurement.rfq'),
        ),
        migrations.CreateModel(
            name='ThreeWayMatch',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('supplier_invoice_no', models.CharField(max_length=64)),
                ('invoice_date', models.DateField()),
                ('ordered_amount', models.DecimalField(decimal_places=2, max_digits=18)),
                ('received_amount', models.DecimalField(decimal_places=2, max_digits=18)),
                ('billed_amount', models.DecimalField(decimal_places=2, max_digits=18)),
                ('tax_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('tds_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('variance_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('within_tolerance', models.BooleanField(default=True)),
                ('variance_reason', models.CharField(blank=True, max_length=255)),
                ('status', models.CharField(choices=[('PENDING', 'Pending Review'), ('VARIANCE_HOLD', 'Variance Exception Hold'), ('MATCHED_POSTED', 'Matched & Posted to GL')], default='PENDING', max_length=20)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='three_way_matches', to='tenancy.company')),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('grn', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='matches', to='inventory.goodsreceiptnote')),
                ('purchase_order', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='matches', to='procurement.purchaseorder')),
                ('voucher', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounting.voucher')),
            ],
            options={
                'db_table': 'purchase_matches',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='VendorProfile',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('vendor_category', models.CharField(choices=[('MATERIALS', 'Construction Materials'), ('EQUIPMENT', 'Machinery & Equipment'), ('CONTRACTOR', 'Subcontractors & Job Work'), ('SERVICES', 'Professional & Site Services')], default='MATERIALS', max_length=20)),
                ('registration_no', models.CharField(blank=True, max_length=64)),
                ('pan_vat_no', models.CharField(blank=True, db_index=True, max_length=20)),
                ('bank_name', models.CharField(blank=True, max_length=120)),
                ('bank_account_no', models.CharField(blank=True, max_length=48)),
                ('bank_branch', models.CharField(blank=True, max_length=100)),
                ('quality_rating', models.DecimalField(decimal_places=2, default=Decimal('4.50'), max_digits=3)),
                ('delivery_rating', models.DecimalField(decimal_places=2, default=Decimal('4.50'), max_digits=3)),
                ('price_rating', models.DecimalField(decimal_places=2, default=Decimal('4.50'), max_digits=3)),
                ('status', models.CharField(choices=[('PENDING', 'Pending Approval'), ('APPROVED', 'Approved'), ('SUSPENDED', 'Suspended'), ('BLACKLISTED', 'Blacklisted')], db_index=True, default='PENDING', max_length=16)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='vendors', to='tenancy.company')),
                ('party', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='vendor_profile', to='accounting.party')),
            ],
            options={
                'db_table': 'vendors',
                'ordering': ['party__name'],
            },
        ),
        migrations.CreateModel(
            name='VendorDocument',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('doc_type', models.CharField(max_length=64)),
                ('doc_number', models.CharField(blank=True, max_length=64)),
                ('file_ref', models.CharField(blank=True, max_length=255)),
                ('issue_date', models.DateField(blank=True, null=True)),
                ('expiry_date', models.DateField(blank=True, null=True)),
                ('vendor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='documents', to='procurement.vendorprofile')),
            ],
            options={
                'db_table': 'vendor_documents',
            },
        ),
        migrations.CreateModel(
            name='VendorContact',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=120)),
                ('designation', models.CharField(blank=True, max_length=80)),
                ('phone', models.CharField(blank=True, max_length=40)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('is_primary', models.BooleanField(default=False)),
                ('vendor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='contacts', to='procurement.vendorprofile')),
            ],
            options={
                'db_table': 'vendor_contacts',
            },
        ),
        migrations.AddField(
            model_name='rfq',
            name='invited_vendors',
            field=models.ManyToManyField(blank=True, related_name='rfqs', to='procurement.vendorprofile'),
        ),
        migrations.CreateModel(
            name='QuotationComparison',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('justification', models.TextField()),
                ('compared_at', models.DateTimeField(auto_now_add=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tenancy.company')),
                ('compared_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
                ('rfq', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='comparison', to='procurement.rfq')),
                ('recommended_vendor', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='procurement.vendorprofile')),
            ],
            options={
                'db_table': 'quotation_comparisons',
            },
        ),
        migrations.AddField(
            model_name='purchaseorder',
            name='vendor',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='purchase_orders', to='procurement.vendorprofile'),
        ),
        migrations.CreateModel(
            name='VendorQuotation',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('quotation_ref', models.CharField(max_length=64)),
                ('quoted_date', models.DateField()),
                ('delivery_days', models.PositiveSmallIntegerField(default=7)),
                ('payment_terms_days', models.PositiveSmallIntegerField(default=30)),
                ('freight_charge', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('tax_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('discount_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('subtotal_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('total_landed_cost', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('technical_compliant', models.BooleanField(default=True)),
                ('warranty_months', models.PositiveSmallIntegerField(default=0)),
                ('attachment_ref', models.CharField(blank=True, max_length=255)),
                ('is_selected', models.BooleanField(default=False)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tenancy.company')),
                ('rfq', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='quotations', to='procurement.rfq')),
                ('vendor', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='quotations', to='procurement.vendorprofile')),
            ],
            options={
                'db_table': 'vendor_quotations',
                'ordering': ['total_landed_cost'],
                'unique_together': {('rfq', 'vendor')},
            },
        ),
        migrations.CreateModel(
            name='VendorQuotationLine',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('description', models.CharField(max_length=220)),
                ('quantity', models.DecimalField(decimal_places=3, max_digits=14)),
                ('unit_rate', models.DecimalField(decimal_places=2, max_digits=14)),
                ('line_total', models.DecimalField(decimal_places=2, max_digits=18)),
                ('item', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='inventory.itemmaster')),
                ('quotation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='procurement.vendorquotation')),
            ],
            options={
                'db_table': 'quotation_lines',
            },
        ),
        migrations.CreateModel(
            name='VendorRating',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('score', models.DecimalField(decimal_places=2, max_digits=3)),
                ('comments', models.CharField(blank=True, max_length=255)),
                ('rated_at', models.DateTimeField(auto_now_add=True)),
                ('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='projects.project')),
                ('rated_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
                ('vendor', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ratings', to='procurement.vendorprofile')),
            ],
            options={
                'db_table': 'vendor_ratings',
            },
        ),
        migrations.AlterUniqueTogether(
            name='rfq',
            unique_together={('company', 'rfq_no')},
        ),
        migrations.AlterUniqueTogether(
            name='purchaseorder',
            unique_together={('company', 'po_number')},
        ),
    ]
