Create print_bill
This commit is contained in:
parent
0b9a543ae2
commit
7b695b1fda
68
api.py
68
api.py
@ -17,7 +17,63 @@ class Info(BaseModel):
|
||||
content : str
|
||||
ip_printer : str
|
||||
|
||||
|
||||
def print_bill(data, address):
|
||||
d = data
|
||||
# Crea una instancia de la impresora ficticia
|
||||
#printer = Network(str(address))
|
||||
#printer.open()
|
||||
printer = Dummy()
|
||||
|
||||
# Imprime el encabezado
|
||||
printer.set(align='center', bold=False, height=1, width=1)
|
||||
printer.text(d["shop_name"]+'\n')
|
||||
printer.text(d["shop_address"]+'\n')
|
||||
printer.text('========================\n')
|
||||
printer.text('\n')
|
||||
printer.text("Cliente: "+d["party"]+'\n')
|
||||
printer.text("CC/NIT: "+d["tax_identifier_code"]+'\n')
|
||||
printer.text("Direccion: "+d["address"]+'\n')
|
||||
printer.text('========================\n')
|
||||
|
||||
for line in d["lines"]:
|
||||
if line['type'] != 'title':
|
||||
text = line['product']
|
||||
printer.text(text)
|
||||
printer.text('\n')
|
||||
text = "cant: " + str(line['quantity']) +" "+ line["uom"] + " $" + line["unit_price"] +"\n"
|
||||
printer.text(text)
|
||||
|
||||
printer.text('========================\n\n')
|
||||
text = "Total (sin impuestos): "+str(d["untaxed_amount"])+"\n"
|
||||
printer.text(text)
|
||||
text = "Impuestos: "+str(d["tax_amount"])+"\n"
|
||||
printer.text(text)
|
||||
text = "Total: "+str(d["total"])+"\n"
|
||||
printer.text(text)
|
||||
printer.text('\n')
|
||||
printer.set(align='center', bold=False, height=1, width=1)
|
||||
printer.text('------------------------\n\n')
|
||||
printer.text("Sigue nuestras redes sociales\n")
|
||||
printer.text("@bicipizza\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")
|
||||
printer.text("Pedido Por: " + str(d['user'])+ '\n')
|
||||
format_date_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
printer.text(str(format_date_time)+'\n')
|
||||
|
||||
# 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
|
||||
|
||||
# Imprime el contenido en la consola
|
||||
sys.stdout.write(ticket_contenido.decode('utf-8'))
|
||||
|
||||
|
||||
|
||||
def print_customer_order(data, address):
|
||||
d = data
|
||||
# Crea una instancia de la impresora ficticia
|
||||
@ -70,6 +126,18 @@ def print_customer_order(data, address):
|
||||
# Imprime el contenido en la consola
|
||||
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"]
|
||||
data = json.loads(data.replace("'", "\""))
|
||||
print_bill(data, address)
|
||||
|
||||
message = "!Impresión Realizada!"
|
||||
|
||||
return Response(content=message, status_code=200)
|
||||
|
||||
@app.post("/order_kitchen")
|
||||
def print_ticket_file_kitchen(info : Info):
|
||||
info = dict(info)
|
||||
|
Loading…
Reference in New Issue
Block a user