add button bill

This commit is contained in:
sinergia 2023-07-25 23:06:21 -05:00
parent 5bb58622c3
commit 1c65c9da81
3 changed files with 60 additions and 1 deletions

55
sale.py
View File

@ -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
@ -59,6 +91,27 @@ class Sale(metaclass=PoolMeta):
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):

View File

@ -32,6 +32,11 @@
<field name="string">Bar</field>
<field name="model" search="[('model', '=', 'sale.sale')]"/>
</record>
<record model="ir.model.button" id="sale_print_bill_button">
<field name="name">print_bill</field>
<field name="string">Bill</field>
<field name="model" search="[('model', '=', 'sale.sale')]"/>
</record>
<record model="ir.action.report" id="report_customer_order">
<field name="name">Customer Order</field>
<field name="model">sale.sale</field>

View File

@ -9,5 +9,6 @@ this repository contains the full copyright notices and license terms. -->
<button name="add_pizza"/>
<button name="kitchen"/>
<button name="bar"/>
<button name="print_bill"/>
</xpath>
</data>