# Generated by Django 4.2.7 on 2025-08-18 02:27

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


class Migration(migrations.Migration):

    initial = True

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

    operations = [
        migrations.CreateModel(
            name='Customer',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=200)),
                ('code', models.CharField(help_text='Unique customer code', max_length=50, unique=True)),
                ('customer_type', models.CharField(choices=[('retail', 'Retail'), ('wholesale', 'Wholesale'), ('distributor', 'Distributor'), ('corporate', 'Corporate')], default='retail', max_length=20)),
                ('contact_person', models.CharField(blank=True, max_length=100)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('phone', models.CharField(blank=True, max_length=20)),
                ('address', models.TextField(blank=True)),
                ('tax_id', models.CharField(blank=True, max_length=50)),
                ('payment_terms', models.CharField(blank=True, help_text='e.g., Net 30, Net 60', max_length=100)),
                ('credit_limit', models.DecimalField(decimal_places=2, default=0, max_digits=12, validators=[django.core.validators.MinValueValidator(Decimal('0'))])),
                ('is_active', models.BooleanField(default=True)),
                ('rating', models.IntegerField(choices=[(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)], default=3, help_text='Customer rating from 1-5')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': 'Customer',
                'verbose_name_plural': 'Customers',
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='SaleOrder',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('order_number', models.CharField(help_text='Unique sales order number', max_length=50, unique=True)),
                ('date', models.DateField()),
                ('expected_delivery_date', models.DateField(blank=True, null=True)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('confirmed', 'Confirmed'), ('shipped', 'Shipped'), ('delivered', 'Delivered'), ('cancelled', 'Cancelled')], default='draft', max_length=20)),
                ('subtotal', models.DecimalField(decimal_places=2, default=0, max_digits=12, validators=[django.core.validators.MinValueValidator(Decimal('0'))])),
                ('tax_amount', models.DecimalField(decimal_places=2, default=0, max_digits=12, validators=[django.core.validators.MinValueValidator(Decimal('0'))])),
                ('discount_amount', models.DecimalField(decimal_places=2, default=0, max_digits=12, validators=[django.core.validators.MinValueValidator(Decimal('0'))])),
                ('shipping_cost', models.DecimalField(decimal_places=2, default=0, max_digits=12, validators=[django.core.validators.MinValueValidator(Decimal('0'))])),
                ('total_amount', models.DecimalField(decimal_places=2, default=0, max_digits=12, validators=[django.core.validators.MinValueValidator(Decimal('0'))])),
                ('notes', models.TextField(blank=True)),
                ('terms_conditions', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sale_orders', to='sales.customer')),
            ],
            options={
                'verbose_name': 'Sales Order',
                'verbose_name_plural': 'Sales Orders',
                'ordering': ['-date', '-created_at'],
            },
        ),
        migrations.CreateModel(
            name='SaleOrderItem',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantity', models.DecimalField(decimal_places=2, max_digits=10, validators=[django.core.validators.MinValueValidator(Decimal('0.01'))])),
                ('unit_price', models.DecimalField(decimal_places=2, max_digits=10, validators=[django.core.validators.MinValueValidator(Decimal('0'))])),
                ('discount_percent', models.DecimalField(decimal_places=2, default=0, help_text='Discount percentage (0-100)', max_digits=5, validators=[django.core.validators.MinValueValidator(Decimal('0'))])),
                ('total_price', models.DecimalField(decimal_places=2, max_digits=12, validators=[django.core.validators.MinValueValidator(Decimal('0'))])),
                ('description', models.CharField(blank=True, max_length=200)),
                ('notes', models.TextField(blank=True)),
                ('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sale_order_items', to='inventory.product')),
                ('sale_order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='sales.saleorder')),
            ],
            options={
                'verbose_name': 'Sales Order Item',
                'verbose_name_plural': 'Sales Order Items',
            },
        ),
        migrations.CreateModel(
            name='DeliveryNote',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('delivery_number', models.CharField(max_length=50, unique=True)),
                ('delivery_date', models.DateField()),
                ('shipping_method', models.CharField(blank=True, max_length=100)),
                ('tracking_number', models.CharField(blank=True, max_length=100)),
                ('notes', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('delivered_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('sale_order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='deliveries', to='sales.saleorder')),
            ],
            options={
                'verbose_name': 'Delivery Note',
                'verbose_name_plural': 'Delivery Notes',
                'ordering': ['-delivery_date'],
            },
        ),
    ]
