refactor(backend): drop the legacy products.printer_zone_id and its print fallbacks
Routing has been by prep zone only since v1, which nulled this column on every start, so the four fallbacks in printer_service.py never ran. Revision 0012 drops the column (its unnamed FK goes with the batch rebuild). The unused legacy GET /api/kds/items keeps its single 'no zone' group. Product create/update/export/import no longer mention it. Scheduled in plan step 1.0 for the catalogue rework (1.13). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
"""drop legacy products.printer_zone_id (plan step 1.13; noted in 1.0)
|
||||||
|
|
||||||
|
Hand-edited: the FK is unnamed, so it can't be dropped by name in SQLite batch mode; the
|
||||||
|
batch rebuild of `products` drops it together with the column. Routing has been by prep
|
||||||
|
zone only since v1 (v1 nulled this column on every start), so no data is lost.
|
||||||
|
|
||||||
|
Revision ID: 0012_drop_product_printer_zone
|
||||||
|
Revises: 0011_order_item_names
|
||||||
|
Create Date: 2026-11-13 12:27:34.824101
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
revision = '0012_drop_product_printer_zone'
|
||||||
|
down_revision = '0011_order_item_names'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('products', schema=None) as batch_op:
|
||||||
|
batch_op.drop_column('printer_zone_id')
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('products', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('printer_zone_id', sa.INTEGER(), nullable=True))
|
||||||
|
batch_op.create_foreign_key('fk_products_printer_zone_id', 'printers', ['printer_zone_id'], ['id'])
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -16,7 +16,6 @@ class Printer(Base):
|
|||||||
duplicates = Column(Integer, default=0, nullable=False)
|
duplicates = Column(Integer, default=0, nullable=False)
|
||||||
codepage_n = Column(Integer, default=29, nullable=False)
|
codepage_n = Column(Integer, default=29, nullable=False)
|
||||||
|
|
||||||
products = relationship("Product", back_populates="printer_zone")
|
|
||||||
print_logs = relationship("PrintLog", back_populates="printer")
|
print_logs = relationship("PrintLog", back_populates="printer")
|
||||||
print_jobs = relationship("PrintJob", back_populates="printer")
|
print_jobs = relationship("PrintJob", back_populates="printer")
|
||||||
prep_zones = relationship("PrepZone", secondary="prep_zone_printers", back_populates="printers")
|
prep_zones = relationship("PrepZone", secondary="prep_zone_printers", back_populates="printers")
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ class Product(Base):
|
|||||||
is_available = Column(Boolean, default=True, nullable=False)
|
is_available = Column(Boolean, default=True, nullable=False)
|
||||||
# "active" | "archived" — archived products are kept for order history but hidden from active use
|
# "active" | "archived" — archived products are kept for order history but hidden from active use
|
||||||
lifecycle_status = Column(String, default="active", nullable=False)
|
lifecycle_status = Column(String, default="active", nullable=False)
|
||||||
printer_zone_id = Column(Integer, ForeignKey("printers.id"), nullable=True)
|
|
||||||
image_url = Column(String, nullable=True)
|
image_url = Column(String, nullable=True)
|
||||||
sort_order = Column(Integer, default=0, nullable=False)
|
sort_order = Column(Integer, default=0, nullable=False)
|
||||||
|
|
||||||
@@ -70,7 +69,6 @@ class Product(Base):
|
|||||||
fiscal_vat_group_id = Column(Integer, nullable=True) # machine VAT group ID (1-based integer)
|
fiscal_vat_group_id = Column(Integer, nullable=True) # machine VAT group ID (1-based integer)
|
||||||
|
|
||||||
category = relationship("Category", back_populates="products")
|
category = relationship("Category", back_populates="products")
|
||||||
printer_zone = relationship("Printer", back_populates="products")
|
|
||||||
prep_zones = relationship("PrepZone", secondary="product_prep_zones", back_populates="products")
|
prep_zones = relationship("PrepZone", secondary="product_prep_zones", back_populates="products")
|
||||||
quick_options = relationship("ProductQuickOption", back_populates="product", cascade="all, delete-orphan")
|
quick_options = relationship("ProductQuickOption", back_populates="product", cascade="all, delete-orphan")
|
||||||
options = relationship("ProductOption", back_populates="product", cascade="all, delete-orphan")
|
options = relationship("ProductOption", back_populates="product", cascade="all, delete-orphan")
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ def _serialize_product(p: Product) -> dict:
|
|||||||
return {
|
return {
|
||||||
"name": p.name, "base_price": p.base_price, "is_available": p.is_available,
|
"name": p.name, "base_price": p.base_price, "is_available": p.is_available,
|
||||||
"lifecycle_status": p.lifecycle_status, "sort_order": p.sort_order,
|
"lifecycle_status": p.lifecycle_status, "sort_order": p.sort_order,
|
||||||
"printer_zone_id": None, # always stripped on export
|
|
||||||
"quick_options": quick_options, "options": options,
|
"quick_options": quick_options, "options": options,
|
||||||
"ingredients": ingredients, "preference_sets": preference_sets,
|
"ingredients": ingredients, "preference_sets": preference_sets,
|
||||||
}
|
}
|
||||||
@@ -179,7 +178,6 @@ def import_catalog(payload: dict, db: Session = Depends(get_db), user: User = De
|
|||||||
existing.lifecycle_status = prod_data.get("lifecycle_status", "active")
|
existing.lifecycle_status = prod_data.get("lifecycle_status", "active")
|
||||||
existing.sort_order = prod_data.get("sort_order", 0)
|
existing.sort_order = prod_data.get("sort_order", 0)
|
||||||
existing.category_id = category_id
|
existing.category_id = category_id
|
||||||
existing.printer_zone_id = None
|
|
||||||
db.flush()
|
db.flush()
|
||||||
product = existing
|
product = existing
|
||||||
else:
|
else:
|
||||||
@@ -190,7 +188,6 @@ def import_catalog(payload: dict, db: Session = Depends(get_db), user: User = De
|
|||||||
lifecycle_status=prod_data.get("lifecycle_status", "active"),
|
lifecycle_status=prod_data.get("lifecycle_status", "active"),
|
||||||
sort_order=prod_data.get("sort_order", 0),
|
sort_order=prod_data.get("sort_order", 0),
|
||||||
category_id=category_id,
|
category_id=category_id,
|
||||||
printer_zone_id=None,
|
|
||||||
)
|
)
|
||||||
db.add(product)
|
db.add(product)
|
||||||
db.flush()
|
db.flush()
|
||||||
|
|||||||
@@ -771,7 +771,7 @@ def kds_items(
|
|||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
product = item.product
|
product = item.product
|
||||||
zone_id = product.printer_zone_id if product else None
|
zone_id = None # legacy per-product printer is gone (routing is by prep zone); one group, as before
|
||||||
zkey = _zone_key(zone_id)
|
zkey = _zone_key(zone_id)
|
||||||
if zkey not in zones:
|
if zkey not in zones:
|
||||||
zones[zkey] = {"zone_id": zone_id, "zone_name": _zone_name(zone_id), "items": []}
|
zones[zkey] = {"zone_id": zone_id, "zone_name": _zone_name(zone_id), "items": []}
|
||||||
|
|||||||
@@ -360,8 +360,6 @@ def update_product(product_id: int, body: ProductUpdate, db: Session = Depends(g
|
|||||||
)
|
)
|
||||||
for field, value in scalar_fields.items():
|
for field, value in scalar_fields.items():
|
||||||
setattr(product, field, value)
|
setattr(product, field, value)
|
||||||
# Always clear legacy per-product printer — routing is now via prep zones only
|
|
||||||
product.printer_zone_id = None
|
|
||||||
# Update prep zones if provided
|
# Update prep zones if provided
|
||||||
if body.prep_zone_ids is not None:
|
if body.prep_zone_ids is not None:
|
||||||
zones = db.query(PrepZone).filter(PrepZone.id.in_(body.prep_zone_ids)).all()
|
zones = db.query(PrepZone).filter(PrepZone.id.in_(body.prep_zone_ids)).all()
|
||||||
|
|||||||
@@ -317,7 +317,6 @@ class ProductBase(BaseModel):
|
|||||||
unit_type: str = "piece"
|
unit_type: str = "piece"
|
||||||
is_available: bool = True
|
is_available: bool = True
|
||||||
lifecycle_status: str = "active"
|
lifecycle_status: str = "active"
|
||||||
printer_zone_id: Optional[int] = None # kept for backward compat; use prep_zone_ids instead
|
|
||||||
prep_zone_ids: List[int] = []
|
prep_zone_ids: List[int] = []
|
||||||
sort_order: int = 0
|
sort_order: int = 0
|
||||||
# Xenia Connect — digital menu overrides
|
# Xenia Connect — digital menu overrides
|
||||||
@@ -359,7 +358,6 @@ class ProductUpdate(BaseModel):
|
|||||||
unit_type: Optional[str] = None
|
unit_type: Optional[str] = None
|
||||||
is_available: Optional[bool] = None
|
is_available: Optional[bool] = None
|
||||||
lifecycle_status: Optional[str] = None
|
lifecycle_status: Optional[str] = None
|
||||||
printer_zone_id: Optional[int] = None
|
|
||||||
prep_zone_ids: Optional[List[int]] = None
|
prep_zone_ids: Optional[List[int]] = None
|
||||||
sort_order: Optional[int] = None
|
sort_order: Optional[int] = None
|
||||||
quick_options: Optional[List[ProductQuickOptionCreate]] = None
|
quick_options: Optional[List[ProductQuickOptionCreate]] = None
|
||||||
@@ -426,7 +424,6 @@ class ProductOut(ProductBase):
|
|||||||
'unit_type': getattr(data, 'unit_type', 'piece') or 'piece',
|
'unit_type': getattr(data, 'unit_type', 'piece') or 'piece',
|
||||||
'is_available': data.is_available,
|
'is_available': data.is_available,
|
||||||
'lifecycle_status': data.lifecycle_status,
|
'lifecycle_status': data.lifecycle_status,
|
||||||
'printer_zone_id': data.printer_zone_id,
|
|
||||||
'prep_zone_ids': [z.id for z in data.prep_zones] if hasattr(data, 'prep_zones') else [],
|
'prep_zone_ids': [z.id for z in data.prep_zones] if hasattr(data, 'prep_zones') else [],
|
||||||
'sort_order': data.sort_order,
|
'sort_order': data.sort_order,
|
||||||
'image_url': data.image_url,
|
'image_url': data.image_url,
|
||||||
|
|||||||
@@ -447,7 +447,6 @@ def send_test_order_print(ip: str, port: int, db: Session, line_width: int = LIN
|
|||||||
name = _FAKE_NAMES[self._filter_id]
|
name = _FAKE_NAMES[self._filter_id]
|
||||||
unit_type = "piece"
|
unit_type = "piece"
|
||||||
category_id = None
|
category_id = None
|
||||||
printer_zone_id = None
|
|
||||||
return _P()
|
return _P()
|
||||||
return _orig_query(self._model).filter(self._model.id == self._filter_id).first()
|
return _orig_query(self._model).filter(self._model.id == self._filter_id).first()
|
||||||
|
|
||||||
@@ -1409,17 +1408,6 @@ def _do_print_cancellation(order_id: int, item_ids: List[int], db: Session):
|
|||||||
printer_job[job_key][1].append(item)
|
printer_job[job_key][1].append(item)
|
||||||
item_routed = True
|
item_routed = True
|
||||||
|
|
||||||
# Fallback to legacy printer_zone_id
|
|
||||||
if not item_routed and product.printer_zone_id:
|
|
||||||
printer = db.query(Printer).filter(Printer.id == product.printer_zone_id, Printer.is_active == True).first()
|
|
||||||
if printer:
|
|
||||||
key = (printer.id, 0, item.id)
|
|
||||||
if key not in seen:
|
|
||||||
seen.add(key)
|
|
||||||
job_key = (printer.id, 0)
|
|
||||||
if job_key not in printer_job:
|
|
||||||
printer_job[job_key] = (printer, [], None)
|
|
||||||
printer_job[job_key][1].append(item)
|
|
||||||
|
|
||||||
div = load_divider_style(db)
|
div = load_divider_style(db)
|
||||||
|
|
||||||
@@ -1859,20 +1847,6 @@ def _do_route_and_print(order_id: int, item_ids: List[int], db: Session, ephemer
|
|||||||
if product.prep_zones and all((z.auto_print or 'none') == 'none' for z in product.prep_zones):
|
if product.prep_zones and all((z.auto_print or 'none') == 'none' for z in product.prep_zones):
|
||||||
printed_item_ids_no_print.add(item.id)
|
printed_item_ids_no_print.add(item.id)
|
||||||
continue
|
continue
|
||||||
# Fall back to legacy printer_zone_id (single printer, 1 copy, no zone formatting)
|
|
||||||
if product.printer_zone_id:
|
|
||||||
printer = db.query(Printer).filter(Printer.id == product.printer_zone_id, Printer.is_active == True).first()
|
|
||||||
if printer:
|
|
||||||
key = (printer.id, 1, 0, item.id)
|
|
||||||
if key not in seen:
|
|
||||||
seen.add(key)
|
|
||||||
job_key = (printer.id, 1, 0)
|
|
||||||
if job_key not in printer_job:
|
|
||||||
printer_job[job_key] = ([], None)
|
|
||||||
printer_job[job_key][0].append(item)
|
|
||||||
else:
|
|
||||||
unzoned.append(item)
|
|
||||||
else:
|
|
||||||
unzoned.append(item)
|
unzoned.append(item)
|
||||||
|
|
||||||
if unzoned:
|
if unzoned:
|
||||||
@@ -1915,16 +1889,6 @@ def _do_route_and_print(order_id: int, item_ids: List[int], db: Session, ephemer
|
|||||||
job_svc_entries[job_key] = []
|
job_svc_entries[job_key] = []
|
||||||
job_svc_entries[job_key].append(entry)
|
job_svc_entries[job_key].append(entry)
|
||||||
entry_routed = True
|
entry_routed = True
|
||||||
# Fallback: legacy printer_zone_id
|
|
||||||
if not entry_routed and getattr(product, 'printer_zone_id', None):
|
|
||||||
pr = db.query(Printer).filter(Printer.id == product.printer_zone_id, Printer.is_active == True).first()
|
|
||||||
if pr:
|
|
||||||
job_key = (pr.id, 1, 0)
|
|
||||||
if job_key not in printer_job:
|
|
||||||
printer_job[job_key] = ([], None)
|
|
||||||
if job_key not in job_svc_entries:
|
|
||||||
job_svc_entries[job_key] = []
|
|
||||||
job_svc_entries[job_key].append(entry)
|
|
||||||
|
|
||||||
printed_item_ids: set[int] = set()
|
printed_item_ids: set[int] = set()
|
||||||
|
|
||||||
@@ -2071,14 +2035,6 @@ def print_service_items_sync(order: Order, service_entries: List[dict], db: Sess
|
|||||||
printer_job[job_key] = {'printer': pr, 'copies': copies, 'zone': z, 'entries': []}
|
printer_job[job_key] = {'printer': pr, 'copies': copies, 'zone': z, 'entries': []}
|
||||||
printer_job[job_key]['entries'].append({'product': product, 'quantity': quantity})
|
printer_job[job_key]['entries'].append({'product': product, 'quantity': quantity})
|
||||||
|
|
||||||
# Fallback: legacy printer_zone_id
|
|
||||||
if not product.prep_zones and product.printer_zone_id:
|
|
||||||
pr = db.query(Printer).filter(Printer.id == product.printer_zone_id, Printer.is_active == True).first()
|
|
||||||
if pr:
|
|
||||||
job_key = (pr.id, 1, 0)
|
|
||||||
if job_key not in printer_job:
|
|
||||||
printer_job[job_key] = {'printer': pr, 'copies': 1, 'zone': None, 'entries': []}
|
|
||||||
printer_job[job_key]['entries'].append({'product': product, 'quantity': quantity})
|
|
||||||
|
|
||||||
for job_key, job in printer_job.items():
|
for job_key, job in printer_job.items():
|
||||||
pr = job['printer']
|
pr = job['printer']
|
||||||
|
|||||||
Reference in New Issue
Block a user