toteat_service.py 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import toteat.toteat as toteat
  2. from logging import getLogger
  3. logger = getLogger(__name__)
  4. def add_order_item(product_id: str, quantity: int, table_number: int, comment=None):
  5. """Agrega un item a la venta activa de la mesa en Toteat."""
  6. table = toteat.get_table(table_number)
  7. if not table:
  8. logger.error(f"Error: Table {table_number} not found.")
  9. return None
  10. active_sale = toteat.get_active_sale(table)
  11. if not active_sale:
  12. active_sale = toteat.create_sale(table['id'])
  13. if not active_sale:
  14. logger.error(f"Error: Could not create sale for table {table_number}.")
  15. return None
  16. item = toteat.create_item(product_id, quantity, active_sale['id'], comment)
  17. if not item:
  18. logger.error(f"Error: Could not create item for product {product_id}.")
  19. return None
  20. return item
  21. def get_products_by_table(table_number: int):
  22. """Retorna los productos activos de una mesa desde Toteat."""
  23. return toteat.get_table_items(table_number)