Backend: - Add can_cancel_orders to User model and schema - Add global orders.waiter_cancellations_allowed setting (migration) - Cancel endpoints: mark items with cancelled_by/cancelled_at, fire cancellation print - print_cancellation_ticket: routes to same printer zones, prints ΑΚΥΡΩΣΗ banner - Fix cancellations_log: date filter, waiter filter, join syntax - shift/orders: add cancellations count and hours_worked per waiter - _enrich_shift: add cancellations count to shift data - Add cancel-permissions endpoint for PWA Manager dashboard: - Global cancel setting toggle in Settings > Operation > Shift Settings - Per-waiter can_cancel_orders checkbox in staff modal - Manager cancel flow: print confirmation prompt (Ναι/Όχι) in DashboardPage - ShiftsOverview: Ακυρώσεις column per shift - Activity: multi-bar chart with ORDERS/ITEMS/CANCELLATIONS/ΕΣΟΔΑ/ΩΡΕΣ checkboxes, grouped/stacked switch, right X-axis for hours, full waiter name on hover - OrderHistory: cancelled items count column per order - WorkDaySummary drill-down: cancelled items column in orders tab Waiter PWA: - Replace 3 pills with CLEAR | ALL | ACTIONS - ACTIONS opens ItemActionModal for selected items - ItemActionModal: ORDER AGAIN, MOVE TO OTHER TABLE, SPLIT, CANCEL ORDER - ActionsSheet: Cancel Παραγγελίας option (greyed if no permission) - CancelConfirmModal: requires confirmation before cancelling - TableListPage: cancel order from long-press quick modal Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
76 lines
3.3 KiB
Python
76 lines
3.3 KiB
Python
from sqlalchemy import Column, Integer, String, Boolean, DateTime, Float, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime, timezone
|
|
from database import Base
|
|
|
|
|
|
def _utcnow():
|
|
return datetime.now(timezone.utc)
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
username = Column(String, unique=True, nullable=False, index=True)
|
|
pin_hash = Column(String, nullable=False)
|
|
password_hash = Column(String, nullable=True)
|
|
email = Column(String, nullable=True)
|
|
role = Column(String, nullable=False) # 'waiter' | 'manager' | 'sysadmin'
|
|
is_active = Column(Boolean, default=True, nullable=False)
|
|
full_name = Column(String, nullable=True)
|
|
nickname = Column(String, nullable=True)
|
|
mobile_phone = Column(String, nullable=True)
|
|
note = Column(String, nullable=True)
|
|
avatar_url = Column(String, nullable=True)
|
|
created_at = Column(DateTime(timezone=True), default=_utcnow)
|
|
# Phase 2B — payroll
|
|
hourly_rate = Column(Float, nullable=True)
|
|
# Waiter cancellation permission
|
|
can_cancel_orders = Column(Boolean, default=False, nullable=False)
|
|
|
|
orders_opened = relationship("Order", foreign_keys="Order.opened_by", back_populates="opener")
|
|
orders_closed = relationship("Order", foreign_keys="Order.closed_by", back_populates="closer")
|
|
order_items = relationship("OrderItem", foreign_keys="OrderItem.added_by", back_populates="added_by_user")
|
|
items_paid = relationship("OrderItem", foreign_keys="OrderItem.paid_by", back_populates="paid_by_user")
|
|
order_assignments = relationship("OrderWaiter", back_populates="waiter")
|
|
zone_assignments = relationship("WaiterZone", back_populates="waiter", cascade="all, delete-orphan")
|
|
|
|
primary_assignments = relationship(
|
|
"AssistantAssignment",
|
|
foreign_keys="AssistantAssignment.primary_waiter_id",
|
|
back_populates="primary_waiter",
|
|
)
|
|
assistant_assignments = relationship(
|
|
"AssistantAssignment",
|
|
foreign_keys="AssistantAssignment.assistant_waiter_id",
|
|
back_populates="assistant_waiter",
|
|
)
|
|
|
|
|
|
class WaiterZone(Base):
|
|
"""Maps a waiter to a table group they are allowed to operate in.
|
|
If a waiter has NO rows here, they see NOTHING.
|
|
A sentinel row with group_id=NULL means 'all zones'."""
|
|
__tablename__ = "waiter_zones"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
waiter_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
group_id = Column(Integer, ForeignKey("table_groups.id"), nullable=True) # NULL = all zones
|
|
assigned_at = Column(DateTime(timezone=True), default=_utcnow)
|
|
|
|
waiter = relationship("User", back_populates="zone_assignments")
|
|
group = relationship("TableGroup", back_populates="waiter_zones")
|
|
|
|
|
|
class AssistantAssignment(Base):
|
|
__tablename__ = "assistant_assignments"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
primary_waiter_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
assistant_waiter_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
assigned_at = Column(DateTime(timezone=True), default=_utcnow)
|
|
|
|
primary_waiter = relationship("User", foreign_keys=[primary_waiter_id], back_populates="primary_assignments")
|
|
assistant_waiter = relationship("User", foreign_keys=[assistant_waiter_id], back_populates="assistant_assignments")
|