From 7b244fa0daf0551ddaf5560246e7f5ea583ccc74 Mon Sep 17 00:00:00 2001 From: sinergia Date: Wed, 26 Jul 2023 00:36:00 -0500 Subject: [PATCH] add information for print bill ticket --- sale.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/sale.py b/sale.py index d940b5f..43d02bd 100644 --- a/sale.py +++ b/sale.py @@ -36,8 +36,12 @@ class Sale(metaclass=PoolMeta): ctx = Transaction().context report = records[0] User = pool.get('res.user') + Shop = pool.get('sale.shop') data = {} user = User(Transaction().user) + shop = Shop.search([('id', '=', ctx["shop"])])[0] + data["shop_name"] = shop.name + data["shop_address"] = shop.address.street data["user"] = user.name data["party"] = report.party.name data["tax_identifier_type"] = report.party.tax_identifier.type_string @@ -49,10 +53,15 @@ class Sale(metaclass=PoolMeta): 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, - "unit_price": line.unit_price if line.type != 'title' else None, - "taxes": line.taxes[0] if line.type != 'title' and line.taxes else None + "uom": line.unit.symbol if line.type != 'title' else None, + "unit_price": str(line.unit_price) 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 report.lines] + + data["untaxed_amount"] = str(report.untaxed_amount) + data["tax_amount"] = str(report.tax_amount) + data["total"] = str(report.total_amount) + return data def report_customer_order(records): if not records: @@ -106,8 +115,8 @@ class Sale(metaclass=PoolMeta): url = f"http://{printer.api.ip_address}/print_bill" - customer_order = cls.report_customer_order(records) - content = {"content": str(json.dumps(customer_order)), "ip_printer": str(printer.ip_address)} + bill = cls.report_bill(records) + content = {"content": str(json.dumps(bill)), "ip_printer": str(printer.ip_address)} headers = {"accept": 'application/json', 'Content-Type': 'application/json'} response = requests.post(url, data=json.dumps(content), headers=headers)