fix reporting.py

This commit is contained in:
Wilson Gomez 2023-10-07 09:08:50 -05:00
parent 383b24303a
commit 4b6283a7a8
1 changed files with 10 additions and 33 deletions

View File

@ -61,25 +61,16 @@ SSH_PORT = 23
def money(value):
if type(value) != int:
if type(value) is int:
value = int(value)
return '{:,}'.format(value)
dev_printers = {}
if os.name == 'posix' and pyudev:
# context = pyudev.Context()
# for device in context.list_devices():
# if device.subsystem == 'usbmisc':
# # print(device.subsystem, device.sys_path.split('2-1/')[1][0:5], device.device_node)
# dev_printers[str(device.sys_path.split('2-1/')[1][0:5])] = device.device_node
try:
files_usb = os.listdir('/dev/usb')
for fl in files_usb:
if 'lp' in fl:
dev_printers['usb'] = fl
except KeyError:
pass
if os.name == 'posix' and os.path.exists('/dev/usb'):
for fl in os.listdir('/dev/usb'):
if 'lp' in fl:
dev_printers['usb'] = fl
class Receipt(object):
@ -105,6 +96,8 @@ class Receipt(object):
self._delta_locale = context.get('delta_locale')
self._environment = environment
self.order_copies = context.get('order_copies')
self.invoice_copies = context.get('invoice_copies')
self.order_kind = 'dispatch' if environment == 'restaurant' else 'command'
self._row_characters = _ROW_CHARACTERS
if context.get('row_characters'):
@ -156,9 +149,9 @@ class Receipt(object):
except Exception:
host, port = self._device, None
if port:
self._printer = printer.Network(host, port=int(port), timeout=60)
self._printer = printer.Network(host, port=int(port), timeout=15)
else:
self._printer = printer.Network(host, timeout=60)
self._printer = printer.Network(host, timeout=15)
elif self._interface == 'ssh':
self._printer = FileSSH(*self._device.split('@'))
self._printer.open()
@ -212,15 +205,6 @@ class Receipt(object):
def set_printer(self):
try:
status = self.check_status(self._interface, self._device)
if not status:
msg = f'''
Impresora no esta disponible;
revisa la configuracion o conexion de impresora
interface: {self._interface}, device: {self._device}
'''
print(msg)
return msg
if self._interface == 'usb':
if OS_NAME == 'posix':
self._printer = printer.File(
@ -237,13 +221,6 @@ class Receipt(object):
self._printer = printer.Network(host, port=int(port), timeout=15)
else:
self._printer = printer.Network(host, timeout=15)
# elif self._interface == 'ssh':
# self._printer = FileSSH(*self._device.split('@'))
# self._printer.open()
# elif self._interface == 'cups':
# self.conn = cups.Connection()
# self._file = open(TEMP_INVOICE_FILE, 'w')
# self._printer = CupsPrinter(self._file, self._row_characters)
if not self._printer:
msg = "Warning: Can not found Printer!"
self.logger.info("Warning: Can not found Printer!")
@ -413,7 +390,7 @@ class Receipt(object):
def print_header_sale_verification(self, sale):
title = 'VERIFICACION DE CUENTA'
msg = """ESTIMADO CLIENTE UNA VEZ REALICE EL \n PAGO DE LA CUENTA POR \n FAVOR EXIJA SU RESPECTIVA FACTURA"""
msg = """ESTIMADO CLIENTE UNA VEZ REALICE EL \n PAGO DE LA CUENTA POR \n FAVOR EXIJA SU RESPECTIVA FACTURA \n PROPINA VOLUNTARIA"""
self._printer.ln(2)
self._printer.set(custom_size=True, width=2, height=2, align='center')
self._printer.text(title)