feat: the table map (platform-v2 step 6.8, D-31)

- floor_plans / floor_items (0035), tables' plan_id + width/height/rotation/shape;
  /api/floor-plans (set-up, catalog.tables.manage, floor_plans.changed) and
  /api/floor-plans/live (each table's state, guests, waiters, time; zone rule)
- @xenia/floorplan: the drawing (Floor, Item, TableShape, FloorView) and its geometry
  (grid snap in whole cells, outlines, chairs), tested
- manager: Management -> Tables -> Floor plans (editor: drag, grid, irregular floor,
  walls/bar/labels/areas, background picture), Tables page List / Map
- counter POS: Tables List / Map; waiter: Map mode, the list stays the default
- tests: test_floor_plans.py, floor + geometry unit tests, manager/waiter/terminal e2e

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 17:00:45 +02:00
co-authored by Claude Opus 5.5
parent fd3254aa31
commit f4aae6abbc
47 changed files with 2102 additions and 8 deletions
+1
View File
@@ -42,3 +42,4 @@ import models.media # noqa: F401 Media (media library, step 5.1)
import models.display_look # noqa: F401 DisplayLook (customer display looks, step 5.3)
import models.signage # noqa: F401 SignagePlaylist, SignageSlide (signage, step 5.4a)
import models.tablet_order # noqa: F401 TabletOrder (ordering from a menu tablet, step 6.6)
import models.floor_plan # noqa: F401 FloorPlan, FloorItem (the table map, step 6.8)
+58
View File
@@ -0,0 +1,58 @@
"""Floor plans: where the tables stand (plan step 6.8, owner decisions D-31).
A zone (table group) can have several floor plans ("Ground floor", "Terrace"); a plan may also
have no zone. A plan is a canvas `width` × `height` in plan units (1 unit = 1 px at 100%):
- `outline`: the floor's shape as a polygon [[x, y], …] (irregular floors); empty = the whole
rectangle;
- `grid_on` / `grid_size`: with the grid on, the editor snaps positions and sizes to multiples
of `grid_size` (the grid is a help for drawing, the stored positions are plain numbers);
- `media_id`: a picture from the media library drawn under everything (e.g. a top-down photo),
with `background_opacity`.
`FloorItem`s are the things that aren't tables: walls, the bar, labels and areas, each a
rectangle (x, y = its centre) with a rotation. A table's place is on the table itself
(models/table.py: plan_id, floor_x/floor_y = its centre, width/height, rotation, shape).
"""
from sqlalchemy import JSON, Boolean, Column, Float, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from core.timeutil import UTCDateTime, utcnow
from database import Base
ITEM_KINDS = ("wall", "bar", "label", "area")
TABLE_SHAPES = ("round", "square", "long")
class FloorPlan(Base):
__tablename__ = "floor_plans"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False)
group_id = Column(Integer, ForeignKey("table_groups.id", ondelete="SET NULL"), nullable=True, index=True)
sort_order = Column(Integer, nullable=False, default=0)
width = Column(Integer, nullable=False, default=1200)
height = Column(Integer, nullable=False, default=800)
outline = Column(JSON, nullable=True)
grid_on = Column(Boolean, nullable=False, default=False)
grid_size = Column(Integer, nullable=False, default=40)
media_id = Column(Integer, ForeignKey("media.id", ondelete="SET NULL"), nullable=True)
background_opacity = Column(Float, nullable=False, default=0.6)
created_at = Column(UTCDateTime, default=utcnow, nullable=False)
media = relationship("Media")
items = relationship("FloorItem", back_populates="plan", cascade="all, delete-orphan", order_by="FloorItem.id")
class FloorItem(Base):
__tablename__ = "floor_items"
id = Column(Integer, primary_key=True, index=True)
plan_id = Column(Integer, ForeignKey("floor_plans.id", ondelete="CASCADE"), nullable=False, index=True)
kind = Column(String, nullable=False)
x = Column(Float, nullable=False)
y = Column(Float, nullable=False)
width = Column(Float, nullable=False)
height = Column(Float, nullable=False)
rotation = Column(Float, nullable=False, default=0.0)
text = Column(String, nullable=True)
plan = relationship("FloorPlan", back_populates="items")
+6
View File
@@ -25,8 +25,14 @@ class Table(Base):
group_id = Column(Integer, ForeignKey("table_groups.id"), nullable=True)
is_active = Column(Boolean, default=True, nullable=False)
seat_count = Column(Integer, nullable=True)
# its place on a floor plan (6.8, D-31; models/floor_plan.py): floor_x / floor_y = its centre
plan_id = Column(Integer, ForeignKey("floor_plans.id", ondelete="SET NULL"), nullable=True, index=True)
floor_x = Column(Float, nullable=True)
floor_y = Column(Float, nullable=True)
width = Column(Float, nullable=True)
height = Column(Float, nullable=True)
rotation = Column(Float, nullable=True)
shape = Column(String, nullable=True) # round | square | long
# the table's QR code (phase 3S, S.7): a random token in the QR menu link; the cloud gets
# only its sha256 (services/table_qr.py). A new token makes the printed code useless.
qr_token = Column(String, nullable=True, unique=True)