Backend: table groups with prefix/color, auto-numbering, has_active_order flag
TableGroup gains prefix and color columns for display in the PWA zone filter. Table creation now assigns a global auto-increment number; batch creation uses group-local label numbering (avoids gaps/conflicts when adding to existing groups). DELETE table now blocks if an active order exists (soft or hard delete). Hard delete cascades past orders before removing the table row. list_tables enriches each TableOut with has_active_order computed server-side. TableOut no longer requires number in the input payload; TableCreate simplified. Migration runner refactored to give each ALTER TABLE its own connection so a no-op (column already exists) doesn't leave a dirty transaction blocking later migrations. New migrations added for all new columns. Order.print_logs relationship gains cascade="all, delete-orphan" so print logs are removed when an order is deleted. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,40 +4,45 @@ from typing import Optional, List
|
||||
|
||||
class TableGroupCreate(BaseModel):
|
||||
name: str
|
||||
prefix: Optional[str] = None
|
||||
color: Optional[str] = None
|
||||
|
||||
|
||||
class TableGroupUpdate(BaseModel):
|
||||
name: Optional[str] = None
|
||||
prefix: Optional[str] = None
|
||||
color: Optional[str] = None
|
||||
|
||||
|
||||
class TableGroupOut(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
prefix: Optional[str] = None
|
||||
sort_order: int = 0
|
||||
color: Optional[str] = None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class TableBase(BaseModel):
|
||||
number: int
|
||||
label: Optional[str] = None
|
||||
group_id: Optional[int] = None
|
||||
is_active: bool = True
|
||||
|
||||
|
||||
class TableCreate(TableBase):
|
||||
pass
|
||||
class TableCreate(BaseModel):
|
||||
label: Optional[str] = None
|
||||
group_id: Optional[int] = None
|
||||
|
||||
|
||||
class TableBatchCreate(BaseModel):
|
||||
group_id: Optional[int] = None
|
||||
count: int
|
||||
name_prefix: str # e.g. "Out-" → Out-1, Out-2 ...
|
||||
start_number: int = 1
|
||||
name_prefix: str # e.g. "TBL-" → TBL-1, TBL-2 ...
|
||||
# start_number is computed on the backend from existing tables in the group
|
||||
|
||||
|
||||
class TableUpdate(BaseModel):
|
||||
number: Optional[int] = None
|
||||
label: Optional[str] = None
|
||||
group_id: Optional[int] = None
|
||||
is_active: Optional[bool] = None
|
||||
@@ -48,10 +53,15 @@ class TableFloorplanUpdate(BaseModel):
|
||||
floor_y: float
|
||||
|
||||
|
||||
class TableOut(TableBase):
|
||||
class TableOut(BaseModel):
|
||||
id: int
|
||||
number: int
|
||||
label: Optional[str] = None
|
||||
group_id: Optional[int] = None
|
||||
is_active: bool = True
|
||||
floor_x: Optional[float] = None
|
||||
floor_y: Optional[float] = None
|
||||
group: Optional[TableGroupOut] = None
|
||||
has_active_order: bool = False
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
Reference in New Issue
Block a user