Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
50674b797b | |||
|
b17a2b83e9 |
72
api.py
72
api.py
@ -1,6 +1,6 @@
|
||||
from fastapi import FastAPI, Response
|
||||
from escpos.printer import Dummy, Network
|
||||
import sys
|
||||
from escpos.printer import Dummy, Network, Usb
|
||||
# import sys
|
||||
import json
|
||||
|
||||
from pydantic import BaseModel
|
||||
@ -17,15 +17,33 @@ class Info(BaseModel):
|
||||
content: str
|
||||
ip_printer: str
|
||||
user_name: str
|
||||
printer_type: str
|
||||
idVendor: str
|
||||
idProduct: str
|
||||
|
||||
|
||||
def print_bill(data, address, waiter):
|
||||
d = data
|
||||
def open_conexion(info):
|
||||
if info.get('ip_printer'):
|
||||
# Crea una instancia de la impresora de Red
|
||||
printer = Network(str(info.get('ip_printer')))
|
||||
printer.open()
|
||||
elif info.get('idVendor') and info.get('idProduct'):
|
||||
# Crea una instancia de la impresora USB
|
||||
printer = Usb(
|
||||
int(info.get('idVendor')),
|
||||
int(info.get('idProduct')), 0)
|
||||
else:
|
||||
# Crea una instancia de la impresora ficticia
|
||||
# printer = Network(str(address))
|
||||
# printer.open()
|
||||
printer = Dummy()
|
||||
# Imprime el encabezado
|
||||
|
||||
return printer
|
||||
|
||||
|
||||
def print_bill(data, info, waiter=None):
|
||||
d = data
|
||||
|
||||
# Abre Conexión Con la Impresora
|
||||
printer = open_conexion(info)
|
||||
printer.set(align='center', bold=False, height=1, width=1)
|
||||
printer.text(d["shop_name"] + '\n')
|
||||
printer.text(d["shop_address"] + '\n')
|
||||
@ -80,7 +98,7 @@ def print_bill(data, address, waiter):
|
||||
printer.set(align='center', bold=False, height=1, width=1)
|
||||
printer.textln('==============================================\n')
|
||||
printer.text("Sigue nuestras redes sociales\n")
|
||||
printer.text("@bicipizza\n")
|
||||
printer.text("@Rustik\n")
|
||||
printer.text("Recuerde que la propina es voluntaria.\n")
|
||||
printer.text("Gracias por visitarnos, vuelva pronto.\n")
|
||||
printer.text("SOFTWARE POTENCIADO POR ONECLUSTER.ORG.\n")
|
||||
@ -94,17 +112,15 @@ def print_bill(data, address, waiter):
|
||||
printer.cut()
|
||||
printer.close()
|
||||
# Obtiene el contenido del ticket de prueba
|
||||
ticket_contenido = printer.output
|
||||
# ticket_contenido = printer.output
|
||||
# Imprime el contenido en la consola
|
||||
sys.stdout.write(ticket_contenido.decode('utf-8'))
|
||||
# sys.stdout.write(ticket_contenido.decode('utf-8'))
|
||||
|
||||
|
||||
def print_customer_order(data, address, waiter):
|
||||
def print_customer_order(data, info, waiter):
|
||||
d = data
|
||||
# Crea una instancia de la impresora ficticia
|
||||
# printer = Network(str(address))
|
||||
# printer.open()
|
||||
printer = Dummy()
|
||||
# Abre Conexión Con la Impresora
|
||||
printer = open_conexion(info)
|
||||
# Imprime el encabezado
|
||||
printer.set(align='center', bold=False, height=1, width=1)
|
||||
format_date_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
@ -126,17 +142,18 @@ def print_customer_order(data, address, waiter):
|
||||
for line in d["lines"]:
|
||||
if line['type'] != 'title':
|
||||
if combination_pizza and pizza < 2:
|
||||
printer.set(align='center', bold=False, height=2, width=2, custom_size=True)
|
||||
printer.set(align='center', bold=False, height=2, width=2,
|
||||
custom_size=True)
|
||||
pizza += 1
|
||||
elif pizza >= 2:
|
||||
combination_pizza = False
|
||||
printer.set(
|
||||
align='left', bold=False, height=2, width=2, custom_size=True
|
||||
)
|
||||
align='left', bold=False, height=2, width=2,
|
||||
custom_size=True)
|
||||
else:
|
||||
printer.set(
|
||||
align='left', bold=False, height=2, width=2, custom_size=True
|
||||
)
|
||||
align='left', bold=False, height=2, width=2,
|
||||
custom_size=True)
|
||||
|
||||
text = line['product'] + " " + str(line['quantity']) + "\n"
|
||||
printer.text(text)
|
||||
@ -159,20 +176,19 @@ def print_customer_order(data, address, waiter):
|
||||
printer.cut()
|
||||
printer.close()
|
||||
# Obtiene el contenido del ticket de prueba
|
||||
ticket_contenido = printer.output
|
||||
# ticket_contenido = printer.output
|
||||
|
||||
# Imprime el contenido en la consola
|
||||
sys.stdout.write(ticket_contenido.decode('utf-8'))
|
||||
# sys.stdout.write(ticket_contenido.decode('utf-8'))
|
||||
|
||||
|
||||
@app.post("/print_bill")
|
||||
def print_ticket_bill(info: Info):
|
||||
info = dict(info)
|
||||
data = info["content"]
|
||||
address = info["ip_printer"]
|
||||
waiter = info["user_name"]
|
||||
data = json.loads(data.replace("'", "\""))
|
||||
print_bill(data, address, waiter)
|
||||
print_bill(data, info, waiter)
|
||||
|
||||
message = "!Impresión Realizada!"
|
||||
|
||||
@ -182,11 +198,11 @@ def print_ticket_bill(info: Info):
|
||||
@app.post("/order_kitchen")
|
||||
def print_ticket_file_kitchen(info: Info):
|
||||
info = dict(info)
|
||||
print(info)
|
||||
data = info["content"]
|
||||
address = info["ip_printer"]
|
||||
waiter = info["user_name"]
|
||||
data = json.loads(data.replace("'", "\""))
|
||||
print_customer_order(data, address, waiter)
|
||||
print_customer_order(data, info, waiter)
|
||||
|
||||
message = "!Impresión Realizada!"
|
||||
|
||||
@ -195,12 +211,12 @@ def print_ticket_file_kitchen(info: Info):
|
||||
|
||||
@app.post("/order_bar")
|
||||
def print_ticket_file_bar(info: Info):
|
||||
print(info)
|
||||
info = dict(info)
|
||||
data = info["content"]
|
||||
address = info["ip_printer"]
|
||||
waiter = info["user_name"]
|
||||
data = json.loads(data.replace("'", "\""))
|
||||
print_customer_order(data, address, waiter)
|
||||
print_customer_order(data, info, waiter)
|
||||
|
||||
message = "!Impresión Realizada!"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user