Files
xenia-pos-local/local_backend/models/floor_plan.py
T
bonaminandClaude Opus 5.5 f4aae6abbc 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>
2026-11-18 17:00:45 +02:00

59 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""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")