Order lines had no index on their order, orders none on their day/customer/status, and each line's product was loaded to tell a fee apart: with ~3000 orders Customers took ~2 s and Reports -> Days ~15 s. Migration 0038 adds the indexes (models carry index=True), Order.items loads with selectin, sales.lines looks the fee products up once, cancellations and prep-zones load their orders with the lines. Days 15 s -> 0.2 s (a month), customers 2 s -> 0.1 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
31 lines
1.6 KiB
Python
31 lines
1.6 KiB
Python
"""Orders from a menu tablet at a table (plan step 6.6, D-30).
|
|
|
|
Every order a tablet sends is a row: what was sent (`lines`, as the counter's lines by id,
|
|
services/pos_cart.py), its note, the total it was quoted at, and what happened:
|
|
waiting a waiter must confirm it first (the venue's or the tablet's setting)
|
|
sent on the table's order and in the kitchen (`order_id`)
|
|
declined a waiter declined it (`reason` for the guests)
|
|
The rows also give the time limit between two orders from one tablet.
|
|
"""
|
|
from sqlalchemy import JSON, Column, Float, ForeignKey, Integer, String, Text
|
|
|
|
from core.timeutil import UTCDateTime, utcnow
|
|
from database import Base
|
|
|
|
|
|
class TabletOrder(Base):
|
|
__tablename__ = "tablet_orders"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
device_id = Column(Integer, ForeignKey("devices.id", ondelete="SET NULL"), nullable=True, index=True)
|
|
table_id = Column(Integer, ForeignKey("tables.id", ondelete="SET NULL"), nullable=True, index=True)
|
|
lines = Column(JSON, nullable=False, default=list)
|
|
note = Column(Text, nullable=True)
|
|
total = Column(Float, nullable=False, default=0.0)
|
|
status = Column(String, nullable=False, default="waiting", index=True)
|
|
order_id = Column(Integer, ForeignKey("orders.id", ondelete="SET NULL"), nullable=True, index=True)
|
|
reason = Column(String, nullable=True)
|
|
decided_by_id = Column(Integer, ForeignKey("users.id", ondelete="SET NULL"), nullable=True)
|
|
decided_at = Column(UTCDateTime, nullable=True)
|
|
created_at = Column(UTCDateTime, default=utcnow, nullable=False, index=True)
|