From 4f378cbae9e84546f8f80539025bd189037940a5 Mon Sep 17 00:00:00 2001 From: sinergia Date: Sat, 22 Jul 2023 11:27:17 -0500 Subject: [PATCH] add printer by zone --- sale.py | 58 ++++++++++++++++++++++++++++++++++++++++++++---------- tryton.cfg | 1 + 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/sale.py b/sale.py index fe5aa02..e3be7f1 100644 --- a/sale.py +++ b/sale.py @@ -25,6 +25,29 @@ class Sale(metaclass=PoolMeta): def default_pizza_number(cls): return 0 + + def report_customer_order(records): + if not records: + return + + ctx = Transaction().context + report = records[0] + data = {} + data["party"] = report.party.name + data["tax_identifier_type"] = report.party.tax_identifier.type_string + data["tax_identifier_code"] = report.party.tax_identifier.code + data["address"] = report.invoice_address.street + 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] + + return data + + @classmethod @ModelView.button def add_pizza(cls, records): @@ -40,13 +63,21 @@ class Sale(metaclass=PoolMeta): @ModelView.button def kitchen(cls, records): pool = Pool() - Report = pool.get('sale.customer_order', type='report') context = Transaction().context - customer_order = Report.execute(records, context) - raise UserError(str(customer_order)) - content = {'content': customer_order[1].decode('utf-8')} + shop = context['shop'] + Printer = pool.get('sale.printer') + printers = Printer.search([('zone', '=', 'kitchen'), ('shop', '=', shop)]) + + if not printers: + return + + printer = printers[0] + url = f"http://{printer.api.ip_address}/order_kitchen" + + customer_order = cls.report_customer_order(records) + content = {"content": str(json.dumps(customer_order)), "ip_printer": str(printer.ip_address)} headers = {"accept": 'application/json', 'Content-Type': 'application/json'} - url = "http://localhost:5000/order_kitchen" + response = requests.post(url, data=json.dumps(content), headers=headers) #return response.status_code @@ -55,16 +86,23 @@ class Sale(metaclass=PoolMeta): @ModelView.button def bar(cls, records): pool = Pool() - Report = pool.get('sale.customer_order', type='report') context = Transaction().context - customer_order = Report.execute(records, context) + shop = context['shop'] + Printer = pool.get('sale.printer') + printers = Printer.search([('zone', '=', 'bar'), ('shop', '=', shop)]) - content = {'content': customer_order[1].decode('utf-8')} + if not printers: + return + + printer = printers[0] + url = f"http://{printer.api.ip_address}/order_bar" + + customer_order = cls.report_customer_order(records) + content = {"content": str(json.dumps(customer_order)), "ip_printer": str(printer.ip_address)} headers = {"accept": 'application/json', 'Content-Type': 'application/json'} - url = "http://localhost:5000/order_bar" + response = requests.post(url, data=json.dumps(content), headers=headers) - #return response.status_code class Line(metaclass=PoolMeta): diff --git a/tryton.cfg b/tryton.cfg index 7f7e30b..5b729a7 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -5,6 +5,7 @@ depends: product sale sale_supply_production + sale_printer production account_invoice xml: