add button bill
This commit is contained in:
parent
5bb58622c3
commit
1c65c9da81
55
sale.py
55
sale.py
@ -18,21 +18,53 @@ class Sale(metaclass=PoolMeta):
|
|||||||
cls._buttons.update({
|
cls._buttons.update({
|
||||||
'add_pizza': {},
|
'add_pizza': {},
|
||||||
'kitchen': {},
|
'kitchen': {},
|
||||||
'bar': {}
|
'bar': {},
|
||||||
|
'print_bill': {},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def default_pizza_number(cls):
|
def default_pizza_number(cls):
|
||||||
return 0
|
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):
|
def report_customer_order(records):
|
||||||
if not records:
|
if not records:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
pool = Pool()
|
||||||
ctx = Transaction().context
|
ctx = Transaction().context
|
||||||
report = records[0]
|
report = records[0]
|
||||||
|
User = pool.get('res.user')
|
||||||
data = {}
|
data = {}
|
||||||
|
user = User(Transaction().user)
|
||||||
|
data["user"] = user.name
|
||||||
data["party"] = report.party.name
|
data["party"] = report.party.name
|
||||||
data["tax_identifier_type"] = report.party.tax_identifier.type_string
|
data["tax_identifier_type"] = report.party.tax_identifier.type_string
|
||||||
data["tax_identifier_code"] = report.party.tax_identifier.code
|
data["tax_identifier_code"] = report.party.tax_identifier.code
|
||||||
@ -58,7 +90,28 @@ class Sale(metaclass=PoolMeta):
|
|||||||
record.lines += (saleLine(type="title",
|
record.lines += (saleLine(type="title",
|
||||||
description="Pizza Combinada"),)
|
description="Pizza Combinada"),)
|
||||||
record.save()
|
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
|
@classmethod
|
||||||
@ModelView.button
|
@ModelView.button
|
||||||
def kitchen(cls, records):
|
def kitchen(cls, records):
|
||||||
|
5
sale.xml
5
sale.xml
@ -32,6 +32,11 @@
|
|||||||
<field name="string">Bar</field>
|
<field name="string">Bar</field>
|
||||||
<field name="model" search="[('model', '=', 'sale.sale')]"/>
|
<field name="model" search="[('model', '=', 'sale.sale')]"/>
|
||||||
</record>
|
</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">
|
<record model="ir.action.report" id="report_customer_order">
|
||||||
<field name="name">Customer Order</field>
|
<field name="name">Customer Order</field>
|
||||||
<field name="model">sale.sale</field>
|
<field name="model">sale.sale</field>
|
||||||
|
@ -9,5 +9,6 @@ this repository contains the full copyright notices and license terms. -->
|
|||||||
<button name="add_pizza"/>
|
<button name="add_pizza"/>
|
||||||
<button name="kitchen"/>
|
<button name="kitchen"/>
|
||||||
<button name="bar"/>
|
<button name="bar"/>
|
||||||
|
<button name="print_bill"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</data>
|
</data>
|
||||||
|
Loading…
Reference in New Issue
Block a user