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
101
backend/models/field_mapping.py
Normal file
101
backend/models/field_mapping.py
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
from datetime import datetime
|
||||
from sqlalchemy import String, DateTime, ForeignKey, Text, Integer
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from database import Base
|
||||
|
||||
|
||||
class FieldMapping(Base):
|
||||
"""
|
||||
Maps supplier-specific field names to standard invoice/line item fields.
|
||||
|
||||
For example, if a supplier's invoices have "Document No" instead of "Invoice ID",
|
||||
we can create a mapping:
|
||||
source_field="Document No" -> target_field="invoice_number"
|
||||
|
||||
Field types:
|
||||
- invoice: Maps to Invoice model fields (invoice_number, invoice_date, total, etc.)
|
||||
- line_item: Maps to LineItem model fields (description, quantity, amount, etc.)
|
||||
"""
|
||||
__tablename__ = "field_mappings"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
|
||||
# Can be kitchen-wide (supplier_id=null) or supplier-specific
|
||||
kitchen_id: Mapped[int] = mapped_column(ForeignKey("kitchens.id"), nullable=False)
|
||||
supplier_id: Mapped[int] = mapped_column(ForeignKey("suppliers.id"), nullable=True)
|
||||
|
||||
# The field name as it appears in the Azure OCR response
|
||||
source_field: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
|
||||
# The target field in our model (e.g., "invoice_number", "description", "amount")
|
||||
target_field: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
|
||||
# Field type: "invoice" or "line_item"
|
||||
field_type: Mapped[str] = mapped_column(String(20), default="invoice")
|
||||
|
||||
# Optional transformation (for future use): "direct", "date", "currency", "number"
|
||||
transform: Mapped[str] = mapped_column(String(50), default="direct")
|
||||
|
||||
# Priority for applying mappings (higher = applied first)
|
||||
priority: Mapped[int] = mapped_column(Integer, default=0)
|
||||
|
||||
# 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
|
||||
kitchen: Mapped["Kitchen"] = relationship("Kitchen")
|
||||
supplier: Mapped["Supplier"] = relationship("Supplier")
|
||||
|
||||
|
||||
# Standard Azure field names for reference
|
||||
AZURE_INVOICE_FIELDS = [
|
||||
"InvoiceId",
|
||||
"InvoiceDate",
|
||||
"InvoiceTotal",
|
||||
"SubTotal",
|
||||
"TotalTax",
|
||||
"AmountDue",
|
||||
"VendorName",
|
||||
"VendorAddress",
|
||||
"CustomerName",
|
||||
"CustomerAddress",
|
||||
"PurchaseOrder",
|
||||
"DueDate",
|
||||
"ServiceDate",
|
||||
"ServiceStartDate",
|
||||
"ServiceEndDate",
|
||||
]
|
||||
|
||||
AZURE_LINE_ITEM_FIELDS = [
|
||||
"Description",
|
||||
"Quantity",
|
||||
"UnitPrice",
|
||||
"Amount",
|
||||
"ProductCode",
|
||||
"Unit",
|
||||
"Date",
|
||||
"Tax",
|
||||
]
|
||||
|
||||
# Our target fields
|
||||
TARGET_INVOICE_FIELDS = [
|
||||
"invoice_number",
|
||||
"invoice_date",
|
||||
"total",
|
||||
"net_total",
|
||||
"vendor_name",
|
||||
"order_number",
|
||||
]
|
||||
|
||||
TARGET_LINE_ITEM_FIELDS = [
|
||||
"description",
|
||||
"quantity",
|
||||
"unit_price",
|
||||
"amount",
|
||||
"product_code",
|
||||
]
|
||||
|
||||
|
||||
from .user import Kitchen
|
||||
from .supplier import Supplier
|
||||
Loading…
Add table
Add a link
Reference in a new issue