print ticket in true printer
This commit is contained in:
parent
91630d6383
commit
e1c9bcac88
48
api.py
48
api.py
@ -14,49 +14,62 @@ app = FastAPI(
|
||||
|
||||
class Info(BaseModel):
|
||||
content : str
|
||||
address : str
|
||||
ip_printer : str
|
||||
|
||||
|
||||
def imprimir_ticket_de_prueba(data, address):
|
||||
d = data
|
||||
# Crea una instancia de la impresora ficticia
|
||||
printer = Network(str(address))
|
||||
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)
|
||||
|
||||
printer.open()
|
||||
#printer = Dummy()
|
||||
|
||||
# Imprime el encabezado
|
||||
printer.set(align='center', bold=False, height=2, width=2, custom_size=True)
|
||||
printer.text('========================\n')
|
||||
printer.set(align='center', bold=False, height=6, width=6)
|
||||
text = 'MESA: ' + str(d['table'] + "\n\n")
|
||||
text = 'MESA: ' + str(d['table'] + "\n")
|
||||
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"]:
|
||||
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"
|
||||
printer.text(text)
|
||||
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")
|
||||
|
||||
combination_pizza = True
|
||||
pizza = 0
|
||||
# Corta el papel (solo para impresoras que soportan esta función)
|
||||
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("/order_kitchen")
|
||||
def print_ticket_file_kitchen(info : Info):
|
||||
print(info)
|
||||
info = dict(info)
|
||||
|
||||
data = info["content"]
|
||||
address = info["ip_printer"]
|
||||
data = json.loads(data.replace("'", "\""))
|
||||
imprimir_ticket_de_prueba(data)
|
||||
imprimir_ticket_de_prueba(data, address)
|
||||
|
||||
message = "!Impresión Realizada!"
|
||||
|
||||
@ -67,7 +80,8 @@ def print_ticket_file_bar(info : Info):
|
||||
info = dict(info)
|
||||
data = info["content"]
|
||||
data = json.loads(data.replace("'", "\""))
|
||||
imprimir_ticket_de_prueba(data)
|
||||
address = info["ip_printer"]
|
||||
imprimir_ticket_de_prueba(data, address)
|
||||
|
||||
message = "!Impresión Realizada!"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user