fix: clean home
This commit is contained in:
parent
de36aacfd1
commit
32db283e16
73
api.py
73
api.py
@ -4,7 +4,6 @@ import sys
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from time import sleep
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
@ -13,18 +12,19 @@ app = FastAPI(
|
|||||||
version="0.0.1"
|
version="0.0.1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Info(BaseModel):
|
class Info(BaseModel):
|
||||||
content: str
|
content: str
|
||||||
ip_printer: str
|
ip_printer: str
|
||||||
|
user_name: str
|
||||||
|
|
||||||
|
|
||||||
def print_bill(data, address):
|
def print_bill(data, address, waiter):
|
||||||
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.open()
|
# printer.open()
|
||||||
#printer = Dummy()
|
printer = Dummy()
|
||||||
|
|
||||||
# Imprime el encabezado
|
# Imprime el encabezado
|
||||||
printer.set(align='center', bold=False, height=1, width=1)
|
printer.set(align='center', bold=False, height=1, width=1)
|
||||||
printer.text(d["shop_name"]+'\n')
|
printer.text(d["shop_name"]+'\n')
|
||||||
@ -33,17 +33,20 @@ def print_bill(data, address):
|
|||||||
printer.textln('===============================================')
|
printer.textln('===============================================')
|
||||||
|
|
||||||
if d['invoice'] and d['invoice']['resolution']:
|
if d['invoice'] and d['invoice']['resolution']:
|
||||||
text = "Resolucion de Facturacion # "+str(d['invoice']['resolution']['resolution_number']) \
|
text = "Resolucion de Facturacion # " + \
|
||||||
+ "\nValida desde "+d['invoice']['resolution']['valid_date_time_from']+ \
|
str(d['invoice']['resolution']['resolution_number']) \
|
||||||
|
+ "\nValida desde " + \
|
||||||
|
d['invoice']['resolution']['valid_date_time_from'] + \
|
||||||
" hasta "+str(d['invoice']['resolution']['valid_date_time_to'])
|
" hasta "+str(d['invoice']['resolution']['valid_date_time_to'])
|
||||||
printer.textln(text)
|
printer.textln(text)
|
||||||
printer.ln()
|
printer.ln()
|
||||||
text = "Factura #: " + d['invoice']['invoice_number']
|
text = "Factura #: " + d['invoice']['invoice_number']
|
||||||
printer.textln(text)
|
printer.textln(text)
|
||||||
#printer.text('\n')
|
|
||||||
printer.text("Cliente: " + d["party"]+'\n')
|
printer.text("Cliente: " + d["party"]+'\n')
|
||||||
printer.text("CC/NIT: " + d["tax_identifier_code"]+'\n')
|
printer.text("CC/NIT: " + d["tax_identifier_code"]+'\n')
|
||||||
printer.text("Direccion: " + d["address"]+'\n')
|
printer.text("Direccion: " + d["address"]+'\n')
|
||||||
|
text = 'MESA: ' + str(d['table'] + "\n")
|
||||||
|
printer.text(text)
|
||||||
printer.textln('===============================================')
|
printer.textln('===============================================')
|
||||||
printer.ln()
|
printer.ln()
|
||||||
for line in d["lines"]:
|
for line in d["lines"]:
|
||||||
@ -51,12 +54,12 @@ def print_bill(data, address):
|
|||||||
text = line['product']
|
text = line['product']
|
||||||
printer.text(text)
|
printer.text(text)
|
||||||
printer.ln()
|
printer.ln()
|
||||||
text = str(line['quantity']) +" "+" $" + line["unit_price"] +"\n"
|
text = str(line['quantity']) + " " + " $" + \
|
||||||
|
line["unit_price"] + "\n"
|
||||||
printer.text(text)
|
printer.text(text)
|
||||||
|
|
||||||
printer.set(align='right', bold=False, height=1, width=1)
|
printer.set(align='right', bold=False, height=1, width=1)
|
||||||
printer.textln('================================================')
|
printer.textln('================================================')
|
||||||
|
|
||||||
text = "Total (sin impuestos): "+str(d["untaxed_amount"])+"\n"
|
text = "Total (sin impuestos): "+str(d["untaxed_amount"])+"\n"
|
||||||
printer.text(text)
|
printer.text(text)
|
||||||
text = "Impuestos (INC): "+str(d["tax_amount"])+"\n"
|
text = "Impuestos (INC): "+str(d["tax_amount"])+"\n"
|
||||||
@ -64,8 +67,6 @@ def print_bill(data, address):
|
|||||||
text = "Total: "+str(d["total"])+"\n"
|
text = "Total: "+str(d["total"])+"\n"
|
||||||
printer.text(text)
|
printer.text(text)
|
||||||
printer.ln()
|
printer.ln()
|
||||||
#printer.text('\n')
|
|
||||||
#if d['payments']:
|
|
||||||
if 'payments' in d.keys():
|
if 'payments' in d.keys():
|
||||||
printer.textln("Pagos: ")
|
printer.textln("Pagos: ")
|
||||||
printer.textln('================================================')
|
printer.textln('================================================')
|
||||||
@ -73,7 +74,6 @@ def print_bill(data, address):
|
|||||||
for payment in d['payments']:
|
for payment in d['payments']:
|
||||||
text = str(payment["statement"])+" $"+str(payment["amount"])
|
text = str(payment["statement"])+" $"+str(payment["amount"])
|
||||||
printer.textln(text)
|
printer.textln(text)
|
||||||
|
|
||||||
printer.set(align='center', bold=False, height=1, width=1)
|
printer.set(align='center', bold=False, height=1, width=1)
|
||||||
printer.textln('==============================================\n')
|
printer.textln('==============================================\n')
|
||||||
printer.text("Sigue nuestras redes sociales\n")
|
printer.text("Sigue nuestras redes sociales\n")
|
||||||
@ -81,39 +81,40 @@ def print_bill(data, address):
|
|||||||
printer.text("Recuerde que la propina es voluntaria.\n")
|
printer.text("Recuerde que la propina es voluntaria.\n")
|
||||||
printer.text("Gracias por visitarnos, vuelva pronto.\n")
|
printer.text("Gracias por visitarnos, vuelva pronto.\n")
|
||||||
printer.text("SOFTWARE POTENCIADO POR ONECLUSTER.ORG.\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')
|
format_date_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||||
printer.text(str(format_date_time)+'\n')
|
printer.text(str(format_date_time)+'\n')
|
||||||
|
if waiter:
|
||||||
|
printer.text("Atendido Por: \n")
|
||||||
|
printer.text(str(waiter)+'\n')
|
||||||
|
|
||||||
# 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()
|
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'))
|
||||||
|
|
||||||
|
|
||||||
|
def print_customer_order(data, address, waiter):
|
||||||
def print_customer_order(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.open()
|
# printer.open()
|
||||||
#printer = Dummy()
|
printer = Dummy()
|
||||||
|
|
||||||
# Imprime el encabezado
|
# Imprime el encabezado
|
||||||
printer.set(align='center', bold=False, height=1, width=1)
|
printer.set(align='center', bold=False, height=1, width=1)
|
||||||
#printer.text("Pedido Por: " + str(d['user'])+ '\n')
|
|
||||||
format_date_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
format_date_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||||
printer.text(str(format_date_time)+'\n')
|
printer.text(str(format_date_time)+'\n')
|
||||||
|
|
||||||
|
if waiter:
|
||||||
|
printer.text("Pedido Por: \n")
|
||||||
|
printer.text(str(waiter)+'\n')
|
||||||
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)
|
||||||
printer.text('========================\n')
|
printer.text('========================\n')
|
||||||
text = 'MESA: ' + str(d['table'] + "\n")
|
text = 'MESA: ' + str(d['table'] + "\n")
|
||||||
printer.text(text)
|
printer.text(text)
|
||||||
printer.text('========================\n')
|
printer.text('========================\n')
|
||||||
|
|
||||||
printer.set(align='left', bold=False, height=6, width=6)
|
printer.set(align='left', bold=False, height=6, width=6)
|
||||||
combination_pizza = False
|
combination_pizza = False
|
||||||
pizza = 0
|
pizza = 0
|
||||||
@ -128,12 +129,10 @@ def print_customer_order(data, address):
|
|||||||
else:
|
else:
|
||||||
printer.set(align='left', bold=False, height=2, width=2, custom_size=True)
|
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)
|
||||||
if pizza == 2:
|
if pizza == 2:
|
||||||
printer.ln()
|
printer.ln()
|
||||||
#printer.text('\n')
|
|
||||||
pizza = 0
|
pizza = 0
|
||||||
combination_pizza = False
|
combination_pizza = False
|
||||||
else:
|
else:
|
||||||
@ -145,42 +144,48 @@ def print_customer_order(data, address):
|
|||||||
printer.cut()
|
printer.cut()
|
||||||
printer.close()
|
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("/print_bill")
|
@app.post("/print_bill")
|
||||||
def print_ticket_bill(info: Info):
|
def print_ticket_bill(info: Info):
|
||||||
info = dict(info)
|
info = dict(info)
|
||||||
data = info["content"]
|
data = info["content"]
|
||||||
address = info["ip_printer"]
|
address = info["ip_printer"]
|
||||||
|
waiter = info["user_name"]
|
||||||
data = json.loads(data.replace("'", "\""))
|
data = json.loads(data.replace("'", "\""))
|
||||||
print_bill(data, address)
|
print_bill(data, address, waiter)
|
||||||
|
|
||||||
message = "!Impresión Realizada!"
|
message = "!Impresión Realizada!"
|
||||||
|
|
||||||
return Response(content=message, status_code=200)
|
return Response(content=message, status_code=200)
|
||||||
|
|
||||||
|
|
||||||
@app.post("/order_kitchen")
|
@app.post("/order_kitchen")
|
||||||
def print_ticket_file_kitchen(info: Info):
|
def print_ticket_file_kitchen(info: Info):
|
||||||
info = dict(info)
|
info = dict(info)
|
||||||
data = info["content"]
|
data = info["content"]
|
||||||
address = info["ip_printer"]
|
address = info["ip_printer"]
|
||||||
|
waiter = info["user_name"]
|
||||||
data = json.loads(data.replace("'", "\""))
|
data = json.loads(data.replace("'", "\""))
|
||||||
print_customer_order(data, address)
|
print_customer_order(data, address, waiter)
|
||||||
|
|
||||||
message = "!Impresión Realizada!"
|
message = "!Impresión Realizada!"
|
||||||
|
|
||||||
return Response(content=message, status_code=200)
|
return Response(content=message, status_code=200)
|
||||||
|
|
||||||
|
|
||||||
@app.post("/order_bar")
|
@app.post("/order_bar")
|
||||||
def print_ticket_file_bar(info: Info):
|
def print_ticket_file_bar(info: Info):
|
||||||
info = dict(info)
|
info = dict(info)
|
||||||
data = info["content"]
|
data = info["content"]
|
||||||
data = json.loads(data.replace("'", "\""))
|
|
||||||
address = info["ip_printer"]
|
address = info["ip_printer"]
|
||||||
print_customer_order(data, address)
|
waiter = info["user_name"]
|
||||||
|
data = json.loads(data.replace("'", "\""))
|
||||||
|
print_customer_order(data, address, waiter)
|
||||||
|
|
||||||
message = "!Impresión Realizada!"
|
message = "!Impresión Realizada!"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user