# Generated by Django 5.2.19 on 2026-11-29 03:42

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', '0004_account_account_class_account_allow_direct_posting_and_more'),
        ('projects', '0001_initial'),
        ('tenancy', '0002_company_multi_currency_enabled'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='OperationalDocument',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('doc_kind', models.CharField(choices=[('PURCHASE_REQUISITION', 'Purchase Requisition (No GL)'), ('PURCHASE_ORDER', 'Purchase Order (No GL)'), ('GOODS_RECEIPT_NOTE', 'Goods Receipt Note (GRN)'), ('MATERIAL_ISSUE_NOTE', 'Material Issue Note (Perpetual WIP Trigger)'), ('MATERIAL_RETURN_NOTE', 'Material Return Note'), ('SITE_MATERIAL_TRANSFER', 'Site Material Transfer'), ('MEASUREMENT_BOOK', 'Measurement Book (MB)'), ('WORK_ORDER', 'Construction / Subcontract Work Order'), ('JOB_COMPLETION_CERT', 'Job Completion Certificate'), ('DELIVERY_CHALLAN', 'Delivery Challan'), ('SITE_INSPECTION_NOTE', 'Site Quality Inspection Note'), ('PROJECT_PROGRESS_REPORT', 'Project Progress Report'), ('SUBCONTRACTOR_CERTIFICATION', 'Subcontractor Work Certification')], db_index=True, max_length=32)),
                ('doc_number', models.CharField(max_length=48)),
                ('doc_date', models.DateField(db_index=True)),
                ('bs_date', models.CharField(blank=True, max_length=16)),
                ('status', models.CharField(choices=[('DRAFT', 'Draft'), ('SUBMITTED', 'Submitted'), ('APPROVED', 'Approved'), ('COMPLETED', 'Completed'), ('CANCELLED', 'Cancelled')], db_index=True, default='DRAFT', max_length=16)),
                ('total_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('remarks', 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_op_docs', to=settings.AUTH_USER_MODEL)),
                ('branch', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='tenancy.branch')),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='operational_documents', to='tenancy.company')),
                ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='created_op_docs', to=settings.AUTH_USER_MODEL)),
                ('linked_voucher', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='operational_sources', to='accounting.voucher')),
                ('party', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='operational_docs', to='accounting.party')),
                ('project', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='operational_docs', to='projects.project')),
                ('reference_doc', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='child_docs', to='construction_ops.operationaldocument')),
                ('site', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.site')),
                ('target_site', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='incoming_transfers', to='projects.site')),
            ],
            options={
                'db_table': 'construction_operational_docs',
                'ordering': ['-doc_date', '-created_at'],
                'unique_together': {('company', 'doc_kind', 'doc_number')},
            },
        ),
        migrations.CreateModel(
            name='OperationalDocumentLine',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('line_no', models.PositiveSmallIntegerField(default=1)),
                ('item_code', models.CharField(blank=True, max_length=40)),
                ('item_name', models.CharField(max_length=200)),
                ('unit', models.CharField(default='Units', max_length=24)),
                ('quantity', models.DecimalField(decimal_places=3, default=Decimal('0.000'), max_digits=14)),
                ('unit_rate', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=18)),
                ('remarks', models.CharField(blank=True, max_length=255)),
                ('boq_item', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='accounting.boqitem')),
                ('cost_code', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.costcode')),
                ('document', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lines', to='construction_ops.operationaldocument')),
            ],
            options={
                'db_table': 'construction_operational_lines',
                'ordering': ['line_no'],
            },
        ),
        migrations.CreateModel(
            name='InventoryStockBalance',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('item_code', models.CharField(max_length=40)),
                ('item_name', models.CharField(max_length=200)),
                ('unit', models.CharField(default='Units', max_length=24)),
                ('quantity_on_hand', models.DecimalField(decimal_places=3, default=Decimal('0.000'), max_digits=16)),
                ('avg_unit_cost', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tenancy.company')),
                ('site', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='projects.site')),
            ],
            options={
                'db_table': 'construction_inventory_balances',
                'ordering': ['item_code'],
                'unique_together': {('company', 'site', 'item_code')},
            },
        ),
    ]
