feat(backend,waiter,manager): moves between tables and orders on the record

Owner 2026-11-23 (plan 6F.4). services/moves.py: every table transfer, lines moved and orders merged
is an order_moves row with its lines (order_move_items: line, quantity then); OrderItem.split_from_id
links a split part to its line, so a part carries the moves made before the split; combining moves
the removed lines' moves to the kept one. Alembic 0048: the tables, the column, and a backfill from
the audit notes written before (note='backfill'). A split part now also keeps the line's price change,
kitchen state, course, cost and names (it used to restart as pending at the menu price).
GET /api/orders/{id}/moves (the order's path, each line's); GET /api/reports/moves (+ export).
Waiter: a moved order's banner (T2 -> T5), moved lines marked, a line's Move history. Manager: the
order's Moves tab, each moved line's path, Reports -> Moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 08:03:11 +02:00
co-authored by Claude Opus 5.5
parent f87f9ff23c
commit 0a353c5f97
27 changed files with 903 additions and 18 deletions
+34
View File
@@ -133,6 +133,9 @@ class OrderItem(Base):
# Deal binding — which deal created this item, and which original item it's linked to
deal_id = Column(Integer, ForeignKey("deals.id"), nullable=True)
linked_item_id = Column(Integer, ForeignKey("order_items.id"), nullable=True)
# the line this one was cut from (6F.4): a split, a lowered quantity, a split payment; its moves
# before the cut are this line's too (services/moves.py)
split_from_id = Column(Integer, ForeignKey("order_items.id"), nullable=True, index=True)
order = relationship("Order", back_populates="items")
product = relationship("Product", back_populates="order_items")
@@ -261,3 +264,34 @@ def _snapshot_item_names(session, flush_context, instances):
cat = session.get(Category, obj.category_id)
obj.category_name = cat.name if cat else None
class OrderMove(Base):
"""Something moved between tables or orders (owner 2026-11-23, plan 6F.4, services/moves.py):
a whole order to another table (`table_transfer`), chosen lines to another order
(`items_moved`), or one order joined into another (`orders_merged`). Never deleted."""
__tablename__ = "order_moves"
id = Column(Integer, primary_key=True, index=True)
kind = Column(String, nullable=False, index=True) # table_transfer | items_moved | orders_merged
from_order_id = Column(Integer, ForeignKey("orders.id"), nullable=True, index=True)
to_order_id = Column(Integer, ForeignKey("orders.id"), nullable=True, index=True)
from_table_id = Column(Integer, ForeignKey("tables.id"), nullable=True)
to_table_id = Column(Integer, ForeignKey("tables.id"), nullable=True)
by_user_id = Column(Integer, ForeignKey("users.id"), nullable=True)
approved_by_user_id = Column(Integer, ForeignKey("users.id"), nullable=True)
business_day_id = Column(Integer, ForeignKey("business_days.id"), nullable=True, index=True)
at = Column(UTCDateTime, default=utcnow, nullable=False, index=True)
note = Column(Text, nullable=True) # the importer / backfill: where it came from
items = relationship("OrderMoveItem", back_populates="move", cascade="all, delete-orphan")
class OrderMoveItem(Base):
"""A line that went with a move, and how much of it (its quantity at the time)."""
__tablename__ = "order_move_items"
move_id = Column(Integer, ForeignKey("order_moves.id", ondelete="CASCADE"), primary_key=True)
item_id = Column(Integer, ForeignKey("order_items.id"), primary_key=True, index=True)
quantity = Column(Float, nullable=True)
move = relationship("OrderMove", back_populates="items")