From b17a2b83e98b6d98664de40ab2bacc438ea1e02b Mon Sep 17 00:00:00 2001 From: rodia Date: Fri, 22 Dec 2023 07:51:47 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20Se=20a=C3=B1ade=20Tipo=20Usb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/api.py b/api.py index 1ed17f7..7cd2fb2 100644 --- a/api.py +++ b/api.py @@ -15,16 +15,23 @@ app = FastAPI( class Info(BaseModel): content: str + printer_type: str ip_printer: str + idVendor: str + idProduct: str user_name: str -def print_bill(data, address, waiter): +def print_bill(data, address=None, idVendor=None idProduct=None, waiter): d = data # Crea una instancia de la impresora ficticia - # printer = Network(str(address)) - # printer.open() - printer = Dummy() + if address: + printer = Network(str(address)) + elif idVendor and idProduct: + printer = Usb(int(idVendor), int(idProduct), 0) + else: + printer = Dummy() + # Imprime el encabezado printer.set(align='center', bold=False, height=1, width=1) printer.text(d["shop_name"]+'\n') @@ -94,9 +101,9 @@ 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): @@ -170,6 +177,7 @@ 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)