# Generated by Django 5.0.2 on 2025-07-18 10:47

import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

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

    operations = [
        migrations.CreateModel(
            name='Sale',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('total_amount', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
                ('payment_method', models.CharField(choices=[('cash', 'Cash'), ('mpesa', 'M-Pesa'), ('credit', 'Credit'), ('cheque', 'Cheque')], max_length=10)),
                ('sale_date', models.DateTimeField(db_index=True, default=django.utils.timezone.now)),
                ('is_complete', models.BooleanField(default=False)),
                ('cash_given', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)),
                ('change_due', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)),
                ('mpesa_reference', models.CharField(blank=True, max_length=255, null=True)),
                ('credit_amount', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)),
                ('credit_paid_date', models.DateField(blank=True, null=True)),
                ('cheque_number', models.CharField(blank=True, max_length=50, null=True)),
                ('cheque_date', models.DateField(blank=True, null=True)),
                ('cheque_cleared', models.BooleanField(default=False)),
                ('customer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='customers.customer')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-sale_date'],
            },
        ),
        migrations.CreateModel(
            name='SaleItem',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('quantity', models.PositiveIntegerField()),
                ('selling_price', models.DecimalField(decimal_places=2, max_digits=10)),
                ('subtotal', models.DecimalField(decimal_places=2, editable=False, max_digits=10)),
                ('batch', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='inventory.batch')),
                ('product', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='inventory.product')),
                ('sale', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='sales.sale')),
            ],
        ),
    ]
