Spaces:
Running
Running
Download backend/app/models/order.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 2.38 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/app/models/order.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/app/models/order.py
-
curl -L -o order.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/app/models/order.py
2.38 kB
| from sqlmodel import SQLModel, Field, Relationship, Column | |
| from sqlalchemy import String, JSON, Float | |
| from typing import Optional, List, Dict, Any | |
| from datetime import datetime | |
| from uuid import UUID, uuid4 | |
| from enum import Enum | |
| class OrderStatus(str, Enum): | |
| NEW = "new" | |
| PENDING_PAYMENT = "pending_payment" | |
| PAID = "paid" | |
| SHIPPED = "shipped" | |
| COMPLETED = "completed" | |
| CANCELLED = "cancelled" | |
| class Order(SQLModel, table=True): | |
| """ | |
| Represents a customer order. | |
| """ | |
| __tablename__ = "orders" | |
| id: UUID = Field(default_factory=uuid4, primary_key=True) | |
| tenant_id: UUID = Field(foreign_key="tenants.id", index=True) | |
| lead_id: UUID = Field(foreign_key="leads.id", index=True) | |
| # Order Details | |
| status: OrderStatus = Field(default=OrderStatus.NEW) | |
| total_amount: float = Field(default=0.0) | |
| currency: str = Field(default="USD") | |
| # Context | |
| shipping_address: Optional[str] = Field(default=None) | |
| customer_notes: Optional[str] = Field(default=None) | |
| # Store arbitrary data (e.g. payment_link, tracking_code) | |
| meta_data: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON)) | |
| # Timestamps | |
| created_at: datetime = Field(default_factory=datetime.utcnow) | |
| updated_at: datetime = Field(default_factory=datetime.utcnow) | |
| # Relationships | |
| tenant: Optional["Tenant"] = Relationship(back_populates="orders") | |
| lead: Optional["Lead"] = Relationship(back_populates="orders") | |
| items: List["OrderItem"] = Relationship(back_populates="order") | |
| class OrderItem(SQLModel, table=True): | |
| """ | |
| Individual item within an order. | |
| """ | |
| __tablename__ = "order_items" | |
| id: UUID = Field(default_factory=uuid4, primary_key=True) | |
| tenant_id: UUID = Field(foreign_key="tenants.id", index=True) # Redundant but useful for RLS/Partitioning | |
| order_id: UUID = Field(foreign_key="orders.id", index=True) | |
| product_id: Optional[UUID] = Field(default=None, foreign_key="products.id") | |
| # Snapshot of product data at time of order | |
| product_name: str | |
| quantity: int = Field(default=1) | |
| unit_price: float = Field(default=0.0) | |
| total_price: float = Field(default=0.0) | |
| # Relationships | |
| order: Optional[Order] = Relationship(back_populates="items") | |
| product: Optional["Product"] = Relationship(back_populates="order_items") | |