From 60f1eca39aef57262ed863dd126551f36df669a2 Mon Sep 17 00:00:00 2001 From: sinergia Date: Fri, 22 Dec 2023 10:06:37 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20Se=20a=C3=B1aden=20impresiones=20para=20?= =?UTF-8?q?USB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sale.py | 63 +++++++++++++++++++++++++++++++++--------------------- tryton.cfg | 1 + 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/sale.py b/sale.py index 5f9708c..63f85ee 100644 --- a/sale.py +++ b/sale.py @@ -162,7 +162,8 @@ class Sale(metaclass=PoolMeta): "product": line.product.name if line.type != 'title' else None, "quantity": line.quantity if line.type != 'title' else None, "uom": line.unit.symbol if line.type != 'title' else None, - "unit_price": str(line.amount_w_tax) if line.type != 'title' else None, + "unit_price": str(line.amount_w_tax) + if line.type != 'title' else None, "taxes": str(round(line.taxes[0].rate * 100, 2)) + '%' if line.type != 'title' and line.taxes else None } for line in record.lines] @@ -171,7 +172,8 @@ class Sale(metaclass=PoolMeta): data["untaxed_amount"] = str(record.untaxed_amount) data["tax_amount"] = str(record.tax_amount) data["total"] = str(record.total_amount) - data["state"] = "SUBTOTAL" if record.state == "draft" else "CUENTA FINAL" + data["state"] = \ + "SUBTOTAL" if record.state == "draft" else "CUENTA FINAL" if record.payments: data['payments'] = [{ @@ -193,13 +195,6 @@ class Sale(metaclass=PoolMeta): data["city"] = report.invoice_address.subdivision_municipality.name data["zone"] = report.zone.name if report.zone else "" data["table"] = report.table.name if report.table else "" - # data["lines"] = [{ - # 'type': line.type, - # "product": line.product.name if line.type != 'title' else None, - # "quantity": line.quantity if line.type != 'title' else None, - # "uom": line.unit.name if line.type != 'title' else None} - # for line in report.lines] - data["lines"] = [{ 'type': line.type, "product": line.product.name if line.type != 'title' else None, @@ -253,20 +248,26 @@ class Sale(metaclass=PoolMeta): else: user_name = "" - content = {"content": str(json.dumps(bill)), - "user_name": user_name} - + content = { + "content": str(json.dumps(bill)), + "printer_type": "", + "ip_printer": "", + "user_name": user_name, + "idVendor": "", + "idProduct": ""} + if printer.type_ == 'network': + content["printer_type"] = "Network" content["ip_printer"] = str(printer.ip_address), else: if printer.type_ == 'usb': + content["printer_type"] = "USB" content["idVendor"] = str(printer.idVendor) content["idProduct"] = str(printer.idProduct) - + headers = {"accept": 'application/json', 'Content-Type': 'application/json'} - - response = requests.post( + requests.post( url, data=json.dumps(content), headers=headers) @classmethod @@ -284,7 +285,6 @@ class Sale(metaclass=PoolMeta): printer = printers[0] - url = f"http://{printer.api.ip_address}/order_kitchen" customer_order = cls.report_customer_order(records) if 'employee.rec_name' in context.keys(): @@ -292,21 +292,28 @@ class Sale(metaclass=PoolMeta): else: user_name = "" - content = {"content": str(json.dumps(bill)), - "user_name": user_name} - + content = {"content": str(json.dumps(customer_order)), + "printer_type": "", + "ip_printer": "", + "user_name": user_name, + "idVendor": "", + "idProduct": ""} + if printer.type_ == 'network': + content["printer_type"] = "Network" content["ip_printer"] = str(printer.ip_address), else: if printer.type_ == 'usb': + content["printer_type"] = "USB" content["idVendor"] = str(printer.idVendor) content["idProduct"] = str(printer.idProduct) headers = {"accept": 'application/json', 'Content-Type': 'application/json'} cls.impreso([record]) - response = requests.post(url, data=json.dumps(content), - headers=headers) + + requests.post(url, data=json.dumps(content), + headers=headers) @classmethod @ModelView.button @@ -333,13 +340,19 @@ class Sale(metaclass=PoolMeta): user_name = "" content = { - "content": str(json.dumps(bill)), - "user_name": user_name} - + "content": str(json.dumps(customer_order)), + "printer_type": "", + "ip_printer": "", + "user_name": user_name, + "idVendor": "", + "idProduct": ""} + if printer.type_ == 'network': + content["printer_type"] = "Network" content["ip_printer"] = str(printer.ip_address), else: if printer.type_ == 'usb': + content["printer_type"] = "USB" content["idVendor"] = str(printer.idVendor) content["idProduct"] = str(printer.idProduct) @@ -349,6 +362,8 @@ class Sale(metaclass=PoolMeta): response = requests.post(url, data=json.dumps(content), headers=headers) + raise Exception(response) + class Line(metaclass=PoolMeta): "Sale Line Fast Food" diff --git a/tryton.cfg b/tryton.cfg index f89b27a..c164da8 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -10,6 +10,7 @@ depends: production account_invoice sale_shop + sale_pos_table xml: product.xml sale.xml