import decimal

import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("shop_management", "0073_alter_stock_average_retail_price_and_more"),
    ]

    operations = [
        migrations.AddField(
            model_name="supplier",
            name="opening_balance",
            field=models.DecimalField(
                blank=True,
                decimal_places=2,
                default=decimal.Decimal("0"),
                max_digits=14,
            ),
        ),
        migrations.AddField(
            model_name="supplier",
            name="opening_balance_currency",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="suppliers_opening_balance",
                to="shop_management.currency",
            ),
        ),
        migrations.CreateModel(
            name="SupplierBalancePayment",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, blank=True, null=True)),
                ("updated_at", models.DateTimeField(auto_now=True, blank=True, null=True)),
                ("amount", models.DecimalField(decimal_places=2, max_digits=14)),
                (
                    "discount",
                    models.DecimalField(decimal_places=2, default=0, max_digits=14),
                ),
                (
                    "exchange_rate",
                    models.DecimalField(decimal_places=6, default=1, max_digits=20),
                ),
                (
                    "converted_amount",
                    models.DecimalField(decimal_places=2, default=0, max_digits=18),
                ),
                (
                    "payment_date",
                    models.DateTimeField(default=django.utils.timezone.now),
                ),
                ("notes", models.TextField(blank=True, null=True)),
                (
                    "account",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="supplier_balance_payments",
                        to="shop_management.account",
                    ),
                ),
                (
                    "currency",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="supplier_balance_payments",
                        to="shop_management.currency",
                    ),
                ),
                (
                    "supplier",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="balance_payments",
                        to="shop_management.supplier",
                    ),
                ),
            ],
            options={
                "ordering": ["-payment_date"],
            },
        ),
    ]
