add printer by zone
This commit is contained in:
parent
a118d64c71
commit
4f378cbae9
58
sale.py
58
sale.py
@ -25,6 +25,29 @@ class Sale(metaclass=PoolMeta):
|
|||||||
def default_pizza_number(cls):
|
def default_pizza_number(cls):
|
||||||
return 0
|
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
|
@classmethod
|
||||||
@ModelView.button
|
@ModelView.button
|
||||||
def add_pizza(cls, records):
|
def add_pizza(cls, records):
|
||||||
@ -40,13 +63,21 @@ class Sale(metaclass=PoolMeta):
|
|||||||
@ModelView.button
|
@ModelView.button
|
||||||
def kitchen(cls, records):
|
def kitchen(cls, records):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Report = pool.get('sale.customer_order', type='report')
|
|
||||||
context = Transaction().context
|
context = Transaction().context
|
||||||
customer_order = Report.execute(records, context)
|
shop = context['shop']
|
||||||
raise UserError(str(customer_order))
|
Printer = pool.get('sale.printer')
|
||||||
content = {'content': customer_order[1].decode('utf-8')}
|
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'}
|
headers = {"accept": 'application/json', 'Content-Type': 'application/json'}
|
||||||
url = "http://localhost:5000/order_kitchen"
|
|
||||||
response = requests.post(url, data=json.dumps(content), headers=headers)
|
response = requests.post(url, data=json.dumps(content), headers=headers)
|
||||||
|
|
||||||
#return response.status_code
|
#return response.status_code
|
||||||
@ -55,16 +86,23 @@ class Sale(metaclass=PoolMeta):
|
|||||||
@ModelView.button
|
@ModelView.button
|
||||||
def bar(cls, records):
|
def bar(cls, records):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Report = pool.get('sale.customer_order', type='report')
|
|
||||||
context = Transaction().context
|
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'}
|
headers = {"accept": 'application/json', 'Content-Type': 'application/json'}
|
||||||
url = "http://localhost:5000/order_bar"
|
|
||||||
response = requests.post(url, data=json.dumps(content), headers=headers)
|
response = requests.post(url, data=json.dumps(content), headers=headers)
|
||||||
|
|
||||||
#return response.status_code
|
|
||||||
|
|
||||||
|
|
||||||
class Line(metaclass=PoolMeta):
|
class Line(metaclass=PoolMeta):
|
||||||
|
@ -5,6 +5,7 @@ depends:
|
|||||||
product
|
product
|
||||||
sale
|
sale
|
||||||
sale_supply_production
|
sale_supply_production
|
||||||
|
sale_printer
|
||||||
production
|
production
|
||||||
account_invoice
|
account_invoice
|
||||||
xml:
|
xml:
|
||||||
|
Loading…
Reference in New Issue
Block a user