Эх сурвалжийг харах

fix webpage and add dev setting

latapp 9 сар өмнө
parent
commit
3aff34e8b6

+ 2 - 1
public/main/js/app.js

@@ -76,12 +76,13 @@ function initializeLoginModal() {
     loginForm.addEventListener('submit', async (event) => {
         event.preventDefault();
         event.stopPropagation();
+        const fd = new FormData(loginForm);
         if (cacheMode) {
+            userTable = Number(fd.get('table').trim());
             sessionModal.classList.add('hidden');
             initializeApp();
             return;
         }
-        const fd = new FormData(loginForm);
         const email = fd.get('email').trim();
         const pin = fd.get('pin').trim();
         userTable = Number(fd.get('table').trim());

+ 6 - 7
routes/orders.py

@@ -69,7 +69,7 @@ async def printer_order(order: OrderWeb, current_user: User = Depends(get_curren
         logger.error(error_msg)
         return JSONResponse(status_code=500, content={"message": "Error interno del servidor"})
 
-    types = set([CAT_ITEMS[product.type] for product in products])
+    types = set([CAT_ITEMS[product.type or ""] for product in products])
 
     # Printer status validation
     if not DEVELOPMENT:
@@ -84,7 +84,7 @@ async def printer_order(order: OrderWeb, current_user: User = Depends(get_curren
                     target=get_email_sender().send_email,
                     args=(
                         PRINTER_DISCONNECTED_MAIL["subject"],
-                        PRINTER_DISCONNECTED_MAIL["body"].format(location=", ".join([loc.value for loc in printer_status])),
+                        PRINTER_DISCONNECTED_MAIL["body"].format(location=", ".join([loc.value for loc in printer_status])), #type: ignore
                         ["erwinjacimino2003@gmail.com", "mompyn@gmail.com"]
                     ),
                     daemon=True
@@ -231,9 +231,9 @@ async def printer_order(order: OrderWeb, current_user: User = Depends(get_curren
 
     # Print order
     try:
-        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]
+        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]#type: ignore
+        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]#type: ignore
+        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]#type: ignore
 
         if kitchen_items:
             ps.print_order(Order(table=table, items=kitchen_items, customerName=user.name, totalAmount=order.totalAmount, orderDate=order.orderDate), location=Locations.KITCHEN)
@@ -244,8 +244,7 @@ async def printer_order(order: OrderWeb, current_user: User = Depends(get_curren
         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, location=CAT_ITEMS.get())
+         
         
         logger.info(f"Order printed successfully for table {table}")
         

+ 6 - 11
services/print_service.py

@@ -10,6 +10,8 @@ logger = getLogger(__name__)
 user_data_service = DataServiceFactory.get_user_service()
 
 def get_printer_url(location: Locations) -> str:
+    if DEVELOPMENT:
+        return "http://localhost:5005"
     if location == Locations.KITCHEN:
         return "http://localhost:6002"
     elif location == Locations.COCTELERY:
@@ -21,13 +23,6 @@ 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"
 
     printer_url = get_printer_url(location)
 
@@ -132,15 +127,15 @@ def get_status(location: Locations):
         logger.info(f"Printer service status: {'online' if status else 'offline'}")
         
         
-        return status
+        return not not status  # Ensure a boolean is returned
         
     except requests.RequestException as e:
         error_msg = f"Error connecting to printer service: {e}"
         logger.error(error_msg)
-        
-        raise Exception(error_msg)
+
+        return False
     except Exception as e:
         error_msg = f"Unexpected error checking printer status: {e}"
         logger.error(error_msg)
         
-        raise Exception(error_msg)
+        return False