268 lines
11 KiB
Python
268 lines
11 KiB
Python
import django.core.validators
|
|
from django.db import migrations, models
|
|
import django.db.models.deletion
|
|
import uuid
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
initial = True
|
|
|
|
dependencies = []
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
name="DeliveryOverrideCode",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.UUIDField(
|
|
default=uuid.uuid4, editable=False, primary_key=True, serialize=False
|
|
),
|
|
),
|
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
("updated_at", models.DateTimeField(auto_now=True)),
|
|
("code", models.CharField(max_length=32, unique=True)),
|
|
("label", models.CharField(max_length=120)),
|
|
("message_to_customer", models.CharField(blank=True, max_length=240)),
|
|
(
|
|
"max_uses",
|
|
models.PositiveIntegerField(default=0, help_text="0 = unlimited"),
|
|
),
|
|
("usage_count", models.PositiveIntegerField(default=0)),
|
|
("is_active", models.BooleanField(default=True)),
|
|
],
|
|
options={"ordering": ["code"]},
|
|
),
|
|
migrations.CreateModel(
|
|
name="DeliveryZone",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.UUIDField(
|
|
default=uuid.uuid4, editable=False, primary_key=True, serialize=False
|
|
),
|
|
),
|
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
("updated_at", models.DateTimeField(auto_now=True)),
|
|
("label", models.CharField(max_length=120)),
|
|
("postal_code", models.CharField(db_index=True, max_length=10)),
|
|
("is_active", models.BooleanField(default=True)),
|
|
],
|
|
options={"ordering": ["postal_code"], "unique_together": {("postal_code", "label")}},
|
|
),
|
|
migrations.CreateModel(
|
|
name="Order",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.UUIDField(
|
|
default=uuid.uuid4, editable=False, primary_key=True, serialize=False
|
|
),
|
|
),
|
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
("updated_at", models.DateTimeField(auto_now=True)),
|
|
("customer_name", models.CharField(max_length=160)),
|
|
("customer_email", models.EmailField(max_length=254)),
|
|
("customer_phone", models.CharField(blank=True, max_length=32)),
|
|
(
|
|
"fulfillment_method",
|
|
models.CharField(
|
|
choices=[("pickup", "Pickup"), ("delivery", "Delivery")],
|
|
db_index=True,
|
|
max_length=16,
|
|
),
|
|
),
|
|
(
|
|
"status",
|
|
models.CharField(
|
|
choices=[
|
|
("draft", "Draft"),
|
|
("pending", "Pending"),
|
|
("confirmed", "Confirmed"),
|
|
("in_production", "In Production"),
|
|
("ready", "Ready"),
|
|
("completed", "Completed"),
|
|
("cancelled", "Cancelled"),
|
|
],
|
|
db_index=True,
|
|
default="pending",
|
|
max_length=16,
|
|
),
|
|
),
|
|
("scheduled_date", models.DateField(blank=True, null=True)),
|
|
("scheduled_time_slot", models.CharField(blank=True, max_length=64)),
|
|
("delivery_address_line1", models.CharField(blank=True, max_length=160)),
|
|
("delivery_address_line2", models.CharField(blank=True, max_length=160)),
|
|
("delivery_city", models.CharField(blank=True, max_length=80)),
|
|
("delivery_state", models.CharField(blank=True, max_length=32)),
|
|
("delivery_postal_code", models.CharField(blank=True, max_length=16)),
|
|
(
|
|
"subtotal_amount",
|
|
models.DecimalField(
|
|
decimal_places=2,
|
|
default=0,
|
|
max_digits=8,
|
|
validators=[django.core.validators.MinValueValidator(0)],
|
|
),
|
|
),
|
|
(
|
|
"tax_amount",
|
|
models.DecimalField(
|
|
decimal_places=2,
|
|
default=0,
|
|
max_digits=8,
|
|
validators=[django.core.validators.MinValueValidator(0)],
|
|
),
|
|
),
|
|
(
|
|
"delivery_fee_amount",
|
|
models.DecimalField(
|
|
decimal_places=2,
|
|
default=0,
|
|
max_digits=8,
|
|
validators=[django.core.validators.MinValueValidator(0)],
|
|
),
|
|
),
|
|
(
|
|
"discount_amount",
|
|
models.DecimalField(
|
|
decimal_places=2,
|
|
default=0,
|
|
max_digits=8,
|
|
validators=[django.core.validators.MinValueValidator(0)],
|
|
),
|
|
),
|
|
(
|
|
"total_amount",
|
|
models.DecimalField(
|
|
decimal_places=2,
|
|
default=0,
|
|
max_digits=8,
|
|
validators=[django.core.validators.MinValueValidator(0)],
|
|
),
|
|
),
|
|
("notes", models.TextField(blank=True)),
|
|
(
|
|
"delivery_override_code",
|
|
models.ForeignKey(
|
|
blank=True,
|
|
null=True,
|
|
on_delete=django.db.models.deletion.SET_NULL,
|
|
related_name="orders",
|
|
to="commerce.deliveryoverridecode",
|
|
),
|
|
),
|
|
],
|
|
options={"ordering": ["-scheduled_date", "-created_at"]},
|
|
),
|
|
migrations.CreateModel(
|
|
name="ProductCategory",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.UUIDField(
|
|
default=uuid.uuid4, editable=False, primary_key=True, serialize=False
|
|
),
|
|
),
|
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
("updated_at", models.DateTimeField(auto_now=True)),
|
|
("name", models.CharField(max_length=120, unique=True)),
|
|
("slug", models.SlugField(max_length=140, unique=True)),
|
|
("description", models.TextField(blank=True)),
|
|
("display_order", models.PositiveIntegerField(default=0)),
|
|
("is_active", models.BooleanField(default=True)),
|
|
],
|
|
options={
|
|
"ordering": ["display_order", "name"],
|
|
"verbose_name_plural": "Product categories",
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name="Product",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.UUIDField(
|
|
default=uuid.uuid4, editable=False, primary_key=True, serialize=False
|
|
),
|
|
),
|
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
("updated_at", models.DateTimeField(auto_now=True)),
|
|
("name", models.CharField(max_length=160)),
|
|
("slug", models.SlugField(max_length=180, unique=True)),
|
|
("short_description", models.CharField(blank=True, max_length=280)),
|
|
("description", models.TextField(blank=True)),
|
|
("ingredients", models.TextField(blank=True)),
|
|
(
|
|
"allergens",
|
|
models.CharField(
|
|
blank=True,
|
|
help_text="Comma-separated allergen labels.",
|
|
max_length=280,
|
|
),
|
|
),
|
|
("price", models.DecimalField(decimal_places=2, max_digits=8)),
|
|
("inventory_quantity", models.PositiveIntegerField(default=0)),
|
|
("max_per_order", models.PositiveIntegerField(default=6)),
|
|
("is_active", models.BooleanField(default=True)),
|
|
("is_featured", models.BooleanField(default=False)),
|
|
("hero_image", models.ImageField(blank=True, upload_to="products/hero/")),
|
|
(
|
|
"category",
|
|
models.ForeignKey(
|
|
blank=True,
|
|
null=True,
|
|
on_delete=django.db.models.deletion.SET_NULL,
|
|
related_name="products",
|
|
to="commerce.productcategory",
|
|
),
|
|
),
|
|
],
|
|
options={"ordering": ["name"]},
|
|
),
|
|
migrations.CreateModel(
|
|
name="OrderItem",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.UUIDField(
|
|
default=uuid.uuid4, editable=False, primary_key=True, serialize=False
|
|
),
|
|
),
|
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
("updated_at", models.DateTimeField(auto_now=True)),
|
|
("product_name", models.CharField(max_length=160)),
|
|
("product_slug", models.SlugField(max_length=180)),
|
|
("unit_price", models.DecimalField(decimal_places=2, max_digits=8)),
|
|
(
|
|
"quantity",
|
|
models.PositiveIntegerField(
|
|
default=1, validators=[django.core.validators.MinValueValidator(1)]
|
|
),
|
|
),
|
|
(
|
|
"line_subtotal",
|
|
models.DecimalField(decimal_places=2, default=0, max_digits=8),
|
|
),
|
|
(
|
|
"order",
|
|
models.ForeignKey(
|
|
on_delete=django.db.models.deletion.CASCADE,
|
|
related_name="items",
|
|
to="commerce.order",
|
|
),
|
|
),
|
|
(
|
|
"product",
|
|
models.ForeignKey(
|
|
null=True,
|
|
on_delete=django.db.models.deletion.SET_NULL,
|
|
related_name="order_items",
|
|
to="commerce.product",
|
|
),
|
|
),
|
|
],
|
|
options={"ordering": ["product_name"]},
|
|
),
|
|
]
|