|
|
@@ -39,10 +39,42 @@ async def printer_order(order: OrderWeb, current_user: User = Depends(get_curren
|
|
|
logger.info(f"Printer order received from user {current_user.email} for table {order.table}")
|
|
|
|
|
|
|
|
|
+
|
|
|
+ # Extract order data
|
|
|
+ items = order.items
|
|
|
+ table = order.table
|
|
|
+
|
|
|
+ # Input validation
|
|
|
+ if not items or not table:
|
|
|
+ logger.warning(f"Invalid order data from user {current_user.email}: missing items or table")
|
|
|
+ return JSONResponse(status_code=400, content={"message": ErrorResponse.MISSING_FIELDS})
|
|
|
+
|
|
|
+ if not isinstance(table, int):
|
|
|
+ logger.warning(f"Invalid table type from user {current_user.email}: {type(table)}")
|
|
|
+
|
|
|
+ return JSONResponse(status_code=400, content={"message": ErrorResponse.INVALID_TABLE_TYPE})
|
|
|
+
|
|
|
+ logger.info(f"Processing order for table {table} with {len(items)} items")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ # Get products data
|
|
|
+ try:
|
|
|
+ products = product_data_service.get_products([item.id for item in items])
|
|
|
+ logger.info(f"Retrieved {len(products)} products from database")
|
|
|
+
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ error_msg = f"Error retrieving products: {e}"
|
|
|
+ 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])
|
|
|
+
|
|
|
# Printer status validation
|
|
|
if not DEVELOPMENT:
|
|
|
try:
|
|
|
- printer_status = filter(lambda x: x == False, [ps.get_status(Locations.BAR), ps.get_status(Locations.KITCHEN), ps.get_status(Locations.COCTELERY)])
|
|
|
+ printer_status = filter(lambda x: x == False, [ps.get_status(loc) for loc in types])
|
|
|
if not printer_status:
|
|
|
logger.error(f"Printer is not connected. Order from user {current_user.email} cannot be processed.")
|
|
|
|
|
|
@@ -66,36 +98,12 @@ async def printer_order(order: OrderWeb, current_user: User = Depends(get_curren
|
|
|
logger.error(f"Error checking printer status: {e}")
|
|
|
return JSONResponse(status_code=500, content={"message": "Error interno del servidor"})
|
|
|
|
|
|
- # Extract order data
|
|
|
- items = order.items
|
|
|
- table = order.table
|
|
|
|
|
|
# Input validation
|
|
|
- if not items or not table:
|
|
|
- logger.warning(f"Invalid order data from user {current_user.email}: missing items or table")
|
|
|
- return JSONResponse(status_code=400, content={"message": ErrorResponse.MISSING_FIELDS})
|
|
|
-
|
|
|
- if not isinstance(table, int):
|
|
|
- logger.warning(f"Invalid table type from user {current_user.email}: {type(table)}")
|
|
|
-
|
|
|
- return JSONResponse(status_code=400, content={"message": ErrorResponse.INVALID_TABLE_TYPE})
|
|
|
-
|
|
|
- logger.info(f"Processing order for table {table} with {len(items)} items")
|
|
|
-
|
|
|
+
|
|
|
# Add products to Fudo
|
|
|
product_errors = []
|
|
|
|
|
|
- # Get products data
|
|
|
- try:
|
|
|
- products = product_data_service.get_products([item.id for item in items])
|
|
|
- logger.info(f"Retrieved {len(products)} products from database")
|
|
|
-
|
|
|
-
|
|
|
- except Exception as e:
|
|
|
- error_msg = f"Error retrieving products: {e}"
|
|
|
- logger.error(error_msg)
|
|
|
- return JSONResponse(status_code=500, content={"message": "Error interno del servidor"})
|
|
|
-
|
|
|
beers_for_promo = 0
|
|
|
|
|
|
try:
|