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


class Migration(migrations.Migration):
    dependencies = [migrations.swappable_dependency(settings.AUTH_USER_MODEL), ("procurements", "0015_contract_commitment")]
    operations = [
        migrations.AlterField(
            model_name="purchaseorder", name="status",
            field=models.CharField(choices=[("draft", "Draft"), ("sent", "Sent"), ("acknowledged", "Acknowledged"), ("fulfilled", "Fulfilled"), ("cancelled", "Cancelled")], default="draft", max_length=20),
        ),
        migrations.CreateModel(
            name="FinancePosting",
            fields=[
                ("id", models.UUIDField(default=apps.procurements.models.uuid7, editable=False, primary_key=True, serialize=False)),
                ("source_type", models.CharField(max_length=30)),
                ("source_id", models.CharField(max_length=40)),
                ("posting_type", models.CharField(choices=[("accrual", "Accrual"), ("payment", "Payment"), ("reversal", "Reversal")], max_length=20)),
                ("amount", models.DecimalField(decimal_places=2, max_digits=18)),
                ("currency", models.CharField(default="IDR", max_length=10)),
                ("payload", models.JSONField(default=dict)),
                ("status", models.CharField(choices=[("pending", "Pending"), ("posted", "Posted"), ("failed", "Failed")], default="pending", max_length=20)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("created_by", models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name="procurement_finance_postings", to=settings.AUTH_USER_MODEL)),
            ],
            options={"db_table": "procurement_finance_postings", "ordering": ["created_at"]},
        ),
        migrations.AddConstraint(
            model_name="financeposting",
            constraint=models.UniqueConstraint(fields=("source_type", "source_id", "posting_type"), name="unique_procurement_finance_posting"),
        ),
    ]
