Initial kitchen scaffold — Phase 1 kitchen port (build-verified 2026-07-11)
FastAPI backend (Python 3.11, MSSQL ODBC for SambaPOS, Azure DI OCR),
kitchen_db on central PG. React/TS/Vite frontend with navy sidebar layout.
Backend: auth.py (APP_SLUG=kitchen, SimpleNamespace — archive routes use
.kitchen_id/.is_admin without modification), main.py (51 migrations, scheduler,
internal router for KDS bookings feed), api/internal.py, full archive API
(31 routers: invoices, recipes, menus, sambapos, resos, newbook, disputes,
purchase_orders, etc.), models, migrations, OCR pipeline.
kitchen_id pinned to 1 (B1 — single hotel).
Frontend: AuthGate (app=kitchen, token shim for archive compat — B5b pending),
Layout (navy sidebar, 6 sections, Lucide icons, teal --app-primary),
App.tsx (Outlet pattern, UploadApp outside Layout), index.css (full :root block).
strict: false — archive components have type issues; build clean.
Note: 45 archive components call fetch('/api/...') without /kitchen/ prefix
(B5b). Runtime 404s; deferred until after initial testing.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
8d688b459d
10003 changed files with 1928395 additions and 0 deletions
69
backend/models/line_item.py
Normal file
69
backend/models/line_item.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from sqlalchemy import String, DateTime, ForeignKey, Numeric, Integer, Text, Boolean
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from database import Base
|
||||
|
||||
|
||||
class LineItem(Base):
|
||||
__tablename__ = "line_items"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
invoice_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("invoices.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
index=True
|
||||
)
|
||||
|
||||
# Core fields from Azure extraction
|
||||
product_code: Mapped[str] = mapped_column(String(100), nullable=True)
|
||||
description: Mapped[str] = mapped_column(Text, nullable=True)
|
||||
description_alt: Mapped[str] = mapped_column(Text, nullable=True) # Alternative description (Azure content vs value mismatch)
|
||||
unit: Mapped[str] = mapped_column(String(50), nullable=True) # Unit of measure (UN, Box, KG, etc.)
|
||||
quantity: Mapped[Decimal] = mapped_column(Numeric(10, 3), nullable=True) # Delivered quantity
|
||||
order_quantity: Mapped[Decimal] = mapped_column(Numeric(10, 3), nullable=True) # Ordered quantity
|
||||
unit_price: Mapped[Decimal] = mapped_column(Numeric(10, 2), nullable=True)
|
||||
tax_rate: Mapped[str] = mapped_column(String(50), nullable=True) # VAT rate (ZERO, 20.00, No VAT, etc.)
|
||||
tax_amount: Mapped[Decimal] = mapped_column(Numeric(10, 2), nullable=True) # VAT amount
|
||||
amount: Mapped[Decimal] = mapped_column(Numeric(10, 2), nullable=True) # Net line total
|
||||
|
||||
# Ordering for display
|
||||
line_number: Mapped[int] = mapped_column(Integer, default=0)
|
||||
|
||||
# Non-stock flag (excluded from GP calculations)
|
||||
is_non_stock: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
|
||||
# Raw OCR content for this line item (used for pack size parsing)
|
||||
raw_content: Mapped[str] = mapped_column(Text, nullable=True)
|
||||
|
||||
# Pack size fields (parsed from raw_content or manually edited)
|
||||
pack_quantity: Mapped[int] = mapped_column(Integer, nullable=True) # e.g., 120 for "120x15g"
|
||||
unit_size: Mapped[Decimal] = mapped_column(Numeric(10, 3), nullable=True) # e.g., 15 for "120x15g"
|
||||
unit_size_type: Mapped[str] = mapped_column(String(10), nullable=True) # e.g., "g", "kg", "ml", "ltr"
|
||||
portions_per_unit: Mapped[int] = mapped_column(Integer, nullable=True) # User-editable servings per unit (null = not defined)
|
||||
|
||||
# Calculated cost fields
|
||||
cost_per_item: Mapped[Decimal] = mapped_column(Numeric(10, 4), nullable=True) # unit_price / pack_quantity
|
||||
cost_per_portion: Mapped[Decimal] = mapped_column(Numeric(10, 4), nullable=True) # unit_price / (pack_quantity * portions_per_unit)
|
||||
|
||||
# OCR warnings (e.g., "quantity capped from 11112121115 to 999999")
|
||||
ocr_warnings: Mapped[str] = mapped_column(Text, nullable=True)
|
||||
|
||||
# Ingredient mapping (set when user maps line item to ingredient via modal)
|
||||
ingredient_id: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("ingredients.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
index=True
|
||||
)
|
||||
|
||||
# Timestamps
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
invoice: Mapped["Invoice"] = relationship("Invoice", back_populates="line_items")
|
||||
ingredient: Mapped["Ingredient | None"] = relationship("Ingredient", foreign_keys=[ingredient_id])
|
||||
|
||||
|
||||
from .invoice import Invoice
|
||||
from .ingredient import Ingredient
|
||||
Loading…
Add table
Add a link
Reference in a new issue