diff --git a/sale.py b/sale.py
index e805ff8..d940b5f 100644
--- a/sale.py
+++ b/sale.py
@@ -18,21 +18,53 @@ class Sale(metaclass=PoolMeta):
cls._buttons.update({
'add_pizza': {},
'kitchen': {},
- 'bar': {}
+ 'bar': {},
+ 'print_bill': {},
})
+
@classmethod
def default_pizza_number(cls):
return 0
+ def report_bill(records):
+ if not records:
+ return
+
+ pool = Pool()
+ ctx = Transaction().context
+ report = records[0]
+ User = pool.get('res.user')
+ data = {}
+ user = User(Transaction().user)
+ data["user"] = user.name
+ 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,
+ "unit_price": line.unit_price if line.type != 'title' else None,
+ "taxes": line.taxes[0] if line.type != 'title' and line.taxes else None
+ } for line in report.lines]
+
def report_customer_order(records):
if not records:
return
+ pool = Pool()
ctx = Transaction().context
report = records[0]
+ User = pool.get('res.user')
data = {}
+ user = User(Transaction().user)
+ data["user"] = user.name
data["party"] = report.party.name
data["tax_identifier_type"] = report.party.tax_identifier.type_string
data["tax_identifier_code"] = report.party.tax_identifier.code
@@ -58,7 +90,28 @@ class Sale(metaclass=PoolMeta):
record.lines += (saleLine(type="title",
description="Pizza Combinada"),)
record.save()
+
+ @classmethod
+ @ModelView.button
+ def print_bill(cls, records):
+ pool = Pool()
+ context = Transaction().context
+ shop = context['shop']
+ Printer = pool.get('sale.printer')
+ printers = Printer.search([('zone', '=', 'reception'), ('shop', '=', shop)])
+ if not printers:
+ return
+
+ printer = printers[0]
+
+ 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)}
+ headers = {"accept": 'application/json', 'Content-Type': 'application/json'}
+
+ response = requests.post(url, data=json.dumps(content), headers=headers)
+
@classmethod
@ModelView.button
def kitchen(cls, records):
diff --git a/sale.xml b/sale.xml
index 16d75aa..114582c 100644
--- a/sale.xml
+++ b/sale.xml
@@ -32,6 +32,11 @@
Bar
+
+ print_bill
+ Bill
+
+
Customer Order
sale.sale
diff --git a/view/sale_form.xml b/view/sale_form.xml
index 10bae38..b49234c 100644
--- a/view/sale_form.xml
+++ b/view/sale_form.xml
@@ -9,5 +9,6 @@ this repository contains the full copyright notices and license terms. -->
+