| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import requests
- from models.sales import OrderWeb, ItemWeb
- from services.data_service import DataServiceFactory
- from models.items import Order
- user_data_service = DataServiceFactory.get_user_service()
- def print_order(order:Order):
- """Send order to printer"""
- if not order.items or not order.table:
- raise ValueError("Order must have items and a table number.")
- # Prepare the order data for printing
- order_data = {
- "table": order.table,
- "items": [{"name": item.name,"price": item.price, "quantity": item.quantity} for item in order.items],
- "customerName": order.customerName,
- "totalAmount": order.totalAmount,
- "orderDate": order.orderDate
- }
- print("Order data prepared for printing:", order_data)
- # Send the order data to the printer service
- response = requests.post("http://localhost:5004/print", json=order_data)
-
- if response.status_code != 200:
- raise Exception(f"Failed to print order: {response.text}")
- return response.json() # Return the response from the printer service
- def get_status():
- """Get the status of the printer service"""
- try:
- response = requests.get("http://localhost:5004/status")
- data = response.json()
- print("Printer service status:", data)
- if data.get("status"):
- return True
- else:
- return False
- except requests.RequestException as e:
- raise Exception(f"Error connecting to printer service: {e}")
|