fix: Se añaden impresiones para USB

This commit is contained in:
sinergia 2023-12-22 10:06:37 -05:00
parent 522a502268
commit 60f1eca39a
2 changed files with 40 additions and 24 deletions

63
sale.py
View File

@ -162,7 +162,8 @@ class Sale(metaclass=PoolMeta):
"product": line.product.name if line.type != 'title' else None, "product": line.product.name if line.type != 'title' else None,
"quantity": line.quantity if line.type != 'title' else None, "quantity": line.quantity if line.type != 'title' else None,
"uom": line.unit.symbol if line.type != 'title' else None, "uom": line.unit.symbol if line.type != 'title' else None,
"unit_price": str(line.amount_w_tax) if line.type != 'title' else None, "unit_price": str(line.amount_w_tax)
if line.type != 'title' else None,
"taxes": str(round(line.taxes[0].rate * 100, 2)) + '%' "taxes": str(round(line.taxes[0].rate * 100, 2)) + '%'
if line.type != 'title' and line.taxes else None if line.type != 'title' and line.taxes else None
} for line in record.lines] } for line in record.lines]
@ -171,7 +172,8 @@ class Sale(metaclass=PoolMeta):
data["untaxed_amount"] = str(record.untaxed_amount) data["untaxed_amount"] = str(record.untaxed_amount)
data["tax_amount"] = str(record.tax_amount) data["tax_amount"] = str(record.tax_amount)
data["total"] = str(record.total_amount) data["total"] = str(record.total_amount)
data["state"] = "SUBTOTAL" if record.state == "draft" else "CUENTA FINAL" data["state"] = \
"SUBTOTAL" if record.state == "draft" else "CUENTA FINAL"
if record.payments: if record.payments:
data['payments'] = [{ data['payments'] = [{
@ -193,13 +195,6 @@ class Sale(metaclass=PoolMeta):
data["city"] = report.invoice_address.subdivision_municipality.name data["city"] = report.invoice_address.subdivision_municipality.name
data["zone"] = report.zone.name if report.zone else "" data["zone"] = report.zone.name if report.zone else ""
data["table"] = report.table.name if report.table 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]
data["lines"] = [{ data["lines"] = [{
'type': line.type, 'type': line.type,
"product": line.product.name if line.type != 'title' else None, "product": line.product.name if line.type != 'title' else None,
@ -253,20 +248,26 @@ class Sale(metaclass=PoolMeta):
else: else:
user_name = "" user_name = ""
content = {"content": str(json.dumps(bill)), content = {
"user_name": user_name} "content": str(json.dumps(bill)),
"printer_type": "",
"ip_printer": "",
"user_name": user_name,
"idVendor": "",
"idProduct": ""}
if printer.type_ == 'network': if printer.type_ == 'network':
content["printer_type"] = "Network"
content["ip_printer"] = str(printer.ip_address), content["ip_printer"] = str(printer.ip_address),
else: else:
if printer.type_ == 'usb': if printer.type_ == 'usb':
content["printer_type"] = "USB"
content["idVendor"] = str(printer.idVendor) content["idVendor"] = str(printer.idVendor)
content["idProduct"] = str(printer.idProduct) content["idProduct"] = str(printer.idProduct)
headers = {"accept": 'application/json', headers = {"accept": 'application/json',
'Content-Type': 'application/json'} 'Content-Type': 'application/json'}
requests.post(
response = requests.post(
url, data=json.dumps(content), headers=headers) url, data=json.dumps(content), headers=headers)
@classmethod @classmethod
@ -284,7 +285,6 @@ class Sale(metaclass=PoolMeta):
printer = printers[0] printer = printers[0]
url = f"http://{printer.api.ip_address}/order_kitchen" url = f"http://{printer.api.ip_address}/order_kitchen"
customer_order = cls.report_customer_order(records) customer_order = cls.report_customer_order(records)
if 'employee.rec_name' in context.keys(): if 'employee.rec_name' in context.keys():
@ -292,21 +292,28 @@ class Sale(metaclass=PoolMeta):
else: else:
user_name = "" user_name = ""
content = {"content": str(json.dumps(bill)), content = {"content": str(json.dumps(customer_order)),
"user_name": user_name} "printer_type": "",
"ip_printer": "",
"user_name": user_name,
"idVendor": "",
"idProduct": ""}
if printer.type_ == 'network': if printer.type_ == 'network':
content["printer_type"] = "Network"
content["ip_printer"] = str(printer.ip_address), content["ip_printer"] = str(printer.ip_address),
else: else:
if printer.type_ == 'usb': if printer.type_ == 'usb':
content["printer_type"] = "USB"
content["idVendor"] = str(printer.idVendor) content["idVendor"] = str(printer.idVendor)
content["idProduct"] = str(printer.idProduct) content["idProduct"] = str(printer.idProduct)
headers = {"accept": 'application/json', headers = {"accept": 'application/json',
'Content-Type': 'application/json'} 'Content-Type': 'application/json'}
cls.impreso([record]) cls.impreso([record])
response = requests.post(url, data=json.dumps(content),
headers=headers) requests.post(url, data=json.dumps(content),
headers=headers)
@classmethod @classmethod
@ModelView.button @ModelView.button
@ -333,13 +340,19 @@ class Sale(metaclass=PoolMeta):
user_name = "" user_name = ""
content = { content = {
"content": str(json.dumps(bill)), "content": str(json.dumps(customer_order)),
"user_name": user_name} "printer_type": "",
"ip_printer": "",
"user_name": user_name,
"idVendor": "",
"idProduct": ""}
if printer.type_ == 'network': if printer.type_ == 'network':
content["printer_type"] = "Network"
content["ip_printer"] = str(printer.ip_address), content["ip_printer"] = str(printer.ip_address),
else: else:
if printer.type_ == 'usb': if printer.type_ == 'usb':
content["printer_type"] = "USB"
content["idVendor"] = str(printer.idVendor) content["idVendor"] = str(printer.idVendor)
content["idProduct"] = str(printer.idProduct) content["idProduct"] = str(printer.idProduct)
@ -349,6 +362,8 @@ class Sale(metaclass=PoolMeta):
response = requests.post(url, data=json.dumps(content), response = requests.post(url, data=json.dumps(content),
headers=headers) headers=headers)
raise Exception(response)
class Line(metaclass=PoolMeta): class Line(metaclass=PoolMeta):
"Sale Line Fast Food" "Sale Line Fast Food"

View File

@ -10,6 +10,7 @@ depends:
production production
account_invoice account_invoice
sale_shop sale_shop
sale_pos_table
xml: xml:
product.xml product.xml
sale.xml sale.xml