print ticket in true printer
This commit is contained in:
parent
91630d6383
commit
e1c9bcac88
46
api.py
46
api.py
@ -14,49 +14,62 @@ app = FastAPI(
|
|||||||
|
|
||||||
class Info(BaseModel):
|
class Info(BaseModel):
|
||||||
content : str
|
content : str
|
||||||
address : str
|
ip_printer : str
|
||||||
|
|
||||||
|
|
||||||
def imprimir_ticket_de_prueba(data, address):
|
def imprimir_ticket_de_prueba(data, address):
|
||||||
d = data
|
d = data
|
||||||
# Crea una instancia de la impresora ficticia
|
# Crea una instancia de la impresora ficticia
|
||||||
printer = Network(str(address))
|
printer = Network(str(address))
|
||||||
printer = Dummy()
|
printer.open()
|
||||||
|
#printer = Dummy()
|
||||||
# Establece el tamaño de la fuente y otros formatos de impresión
|
|
||||||
printer.set(font='a', align='center', bold=True, height=2, width=2)
|
|
||||||
|
|
||||||
# Imprime el encabezado
|
# Imprime el encabezado
|
||||||
|
printer.set(align='center', bold=False, height=2, width=2, custom_size=True)
|
||||||
printer.text('========================\n')
|
printer.text('========================\n')
|
||||||
printer.set(align='center', bold=False, height=6, width=6)
|
text = 'MESA: ' + str(d['table'] + "\n")
|
||||||
text = 'MESA: ' + str(d['table'] + "\n\n")
|
|
||||||
printer.text(text)
|
printer.text(text)
|
||||||
printer.set(align='left', height=6, width=6)
|
printer.text('========================\n')
|
||||||
|
|
||||||
|
printer.set(align='left', bold=False, height=6, width=6)
|
||||||
|
pizza = None
|
||||||
for line in d["lines"]:
|
for line in d["lines"]:
|
||||||
if line['type'] != 'title':
|
if line['type'] != 'title':
|
||||||
|
if combination_pizza and pizza < 2:
|
||||||
|
printer.set(align='center', bold=False, height=2, width=2, custom_size=True)
|
||||||
|
pizza += 1
|
||||||
|
if pizza == 2:
|
||||||
|
printer.text('\n')
|
||||||
|
elif pizza >=2:
|
||||||
|
combination_pizza = False
|
||||||
|
printer.set(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)
|
||||||
|
|
||||||
text = line['product'] +" "+str(line['quantity'])+"\n"
|
text = line['product'] +" "+str(line['quantity'])+"\n"
|
||||||
printer.text(text)
|
printer.text(text)
|
||||||
else:
|
else:
|
||||||
printer.set(align='left', bold=True, height=8, width=8)
|
printer.set(align='left', bold=True, height=2, width=2, custom_size=True)
|
||||||
printer.text("\nPIZZA COMBINADA\n")
|
printer.text("\nPIZZA COMBINADA\n")
|
||||||
|
combination_pizza = True
|
||||||
|
pizza = 0
|
||||||
# Corta el papel (solo para impresoras que soportan esta función)
|
# Corta el papel (solo para impresoras que soportan esta función)
|
||||||
printer.cut()
|
printer.cut()
|
||||||
|
printer.close()
|
||||||
# Obtiene el contenido del ticket de prueba
|
# Obtiene el contenido del ticket de prueba
|
||||||
ticket_contenido = printer.output
|
#ticket_contenido = printer.output
|
||||||
|
|
||||||
# Imprime el contenido en la consola
|
# Imprime el contenido en la consola
|
||||||
sys.stdout.write(ticket_contenido.decode('utf-8'))
|
#sys.stdout.write(ticket_contenido.decode('utf-8'))
|
||||||
|
|
||||||
@app.post("/order_kitchen")
|
@app.post("/order_kitchen")
|
||||||
def print_ticket_file_kitchen(info : Info):
|
def print_ticket_file_kitchen(info : Info):
|
||||||
print(info)
|
print(info)
|
||||||
info = dict(info)
|
info = dict(info)
|
||||||
|
|
||||||
data = info["content"]
|
data = info["content"]
|
||||||
|
address = info["ip_printer"]
|
||||||
data = json.loads(data.replace("'", "\""))
|
data = json.loads(data.replace("'", "\""))
|
||||||
imprimir_ticket_de_prueba(data)
|
imprimir_ticket_de_prueba(data, address)
|
||||||
|
|
||||||
message = "!Impresión Realizada!"
|
message = "!Impresión Realizada!"
|
||||||
|
|
||||||
@ -67,7 +80,8 @@ def print_ticket_file_bar(info : Info):
|
|||||||
info = dict(info)
|
info = dict(info)
|
||||||
data = info["content"]
|
data = info["content"]
|
||||||
data = json.loads(data.replace("'", "\""))
|
data = json.loads(data.replace("'", "\""))
|
||||||
imprimir_ticket_de_prueba(data)
|
address = info["ip_printer"]
|
||||||
|
imprimir_ticket_de_prueba(data, address)
|
||||||
|
|
||||||
message = "!Impresión Realizada!"
|
message = "!Impresión Realizada!"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user