Переглянути джерело

printer autoroute kitchen, coctelery and bar

latapp 9 місяців тому
батько
коміт
2ea987fdec
4 змінених файлів з 79 додано та 14 видалено
  1. 34 0
      data/product_category.py
  2. 12 0
      enums/locations.py
  3. 16 8
      routes/orders.py
  4. 17 6
      services/print_service.py

+ 34 - 0
data/product_category.py

@@ -0,0 +1,34 @@
+from enums.locations import Locations
+
+CAT_ITEMS = {
+    "Gelatería y Antojitos": Locations.COCTELERY,
+    "Cocteleria de Bar": Locations.COCTELERY,
+    "Inactivos": Locations.BAR,
+    "Gin & Tonic": Locations.COCTELERY,
+    "Pizzas Familiares": Locations.KITCHEN,
+    "Pisco": Locations.COCTELERY,
+    "Hidromiel": Locations.BAR,
+    "Sin Alcohol": Locations.BAR,
+    "Pizza Medianas": Locations.KITCHEN,
+    "Kiosco Klein": Locations.COCTELERY,
+    "Whisky & Whiskey": Locations.BAR,
+    "Coctelería Gin Klein": Locations.COCTELERY,
+    "Vinos & Espumantes": Locations.COCTELERY,
+    "Shop": Locations.BAR,
+    "Sidras": Locations.COCTELERY,
+    "Ron & Vodka": Locations.COCTELERY,
+    "Licores y Otros destilados": Locations.COCTELERY,
+    "Growlers": Locations.BAR,
+    "Coctelería de Autor": Locations.COCTELERY,
+    "Latas": Locations.COCTELERY,
+    "Cafetería": Locations.COCTELERY,
+    "Cortos": Locations.COCTELERY,
+    "Appetizer": Locations.KITCHEN,
+    "Botellas": Locations.BAR,
+    "Almuerzo": Locations.KITCHEN,
+    "Shots": Locations.COCTELERY,
+    "Klein Day": Locations.COCTELERY,
+    "Spritz": Locations.COCTELERY,
+    "Sandwich de Autor": Locations.KITCHEN,
+    "Cervezas": Locations.BAR,
+}

+ 12 - 0
enums/locations.py

@@ -0,0 +1,12 @@
+from enum import Enum
+
+class Locations(Enum):
+    """Locations for the printer service"""
+    KITCHEN = "KITCHEN"
+    BAR = "BAR"
+    COCTELERY = "COCTELERY"
+
+    @classmethod
+    def get_all(cls):
+        """Return all locations as a list"""
+        return [location.value for location in cls]

+ 16 - 8
routes/orders.py

@@ -3,6 +3,7 @@ from logging import getLogger
 from threading import Thread
 from uuid import uuid4
 
+from enums.locations import Locations
 from fastapi import HTTPException, APIRouter, Depends
 from fastapi.responses import JSONResponse
 
@@ -18,6 +19,7 @@ from config.mails import PRINTER_DISCONNECTED_MAIL
 from config.messages import ErrorResponse, SuccessResponse, UserResponse
 from config.settings import DEVELOPMENT
 from auth.security import get_current_user
+from data.product_category import CAT_ITEMS
 
 logger = getLogger(__name__)
 
@@ -221,15 +223,21 @@ async def printer_order(order: OrderWeb, current_user: User = Depends(get_curren
 
     # Print order
     try:
-        order_for_print = Order(
-            table=table,
-            items=[Item(name=product.name, price=product.price or 0, quantity=item.quantity) for product, item in zip(products, items)],
-            customerName=user.name,
-            totalAmount=order.totalAmount,
-            orderDate=order.orderDate
-        )
+        kitchen_items = [ Item(name=item.name, price=product.price, quantity=item.quantity) for product, item in zip(items, products) if CAT_ITEMS.get(item.type, Locations.BAR) == Locations.KITCHEN]
+        bar_items = [ Item(name=item.name, price=product.price, quantity=item.quantity) for product, item in zip(items, products) if CAT_ITEMS.get(item.type, Locations.BAR) == Locations.BAR]
+        coctelery_items = [ Item(name=item.name, price=product.price, quantity=item.quantity) for product, item in zip(items, products) if CAT_ITEMS.get(item.type, Locations.COCTELERY) == Locations.COCTELERY]
+
+        if kitchen_items:
+            ps.print_order(Order(table=table, items=kitchen_items, customerName=user.name, totalAmount=order.totalAmount, orderDate=order.orderDate), location=Locations.KITCHEN)
+            logger.info(f"Order kitchen printed successfully for table {table}")
+        if bar_items:
+            ps.print_order(Order(table=table, items=bar_items, customerName=user.name, totalAmount=order.totalAmount, orderDate=order.orderDate), location=Locations.BAR)
+            logger.info(f"Order bar printed successfully for table {table}")
+        if coctelery_items:
+            ps.print_order(Order(table=table, items=coctelery_items, customerName=user.name, totalAmount=order.totalAmount, orderDate=order.orderDate), location=Locations.COCTELERY)
+            logger.info(f"Order coctelery printed successfully for table {table}")
         
-        ps.print_order(order_for_print)
+        # ps.print_order(order_for_print, location=CAT_ITEMS.get())
         
         logger.info(f"Order printed successfully for table {table}")
         

+ 17 - 6
services/print_service.py

@@ -4,19 +4,30 @@ from config.settings import DEVELOPMENT
 from models.sales import OrderWeb, ItemWeb
 from services.data_service import DataServiceFactory
 from models.items import Order
+from enums.locations import Locations
 
 logger = getLogger(__name__)
 user_data_service = DataServiceFactory.get_user_service()
 
-if DEVELOPMENT:
-    printer_url = "http://localhost:5005/"
-else:
-    printer_url = "http://localhost:5004/"
-
-def print_order(order: Order):
+def print_order(order: Order, location:Locations ):
     """Send order to printer"""
     logger.info(f"Attempting to print order for table {order.table}")
     
+    # match location:
+    #     case Locations.BAR:
+    #         printer_url = "http://localhost:6000"
+    #     case Locations.KITCHEN:
+    #         printer_url = "http://localhost:6002"
+    #     case Locations.COCTELERY:
+    #         printer_url = "http://localhost:6004"
+
+    if location == Locations.KITCHEN:
+        printer_url = "http://localhost:6002"
+    elif location == Locations.COCTELERY:
+        printer_url = "http://localhost:6004"
+    else:
+        printer_url = "http://localhost:6000"
+
     try:
         if not order.items or not order.table:
             error_msg = "Order must have items and a table number"