From 59b5f136bfc2f4b466063b22d7bffd0d0df64ae9 Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Tue, 11 Aug 2015 12:55:27 +0200 Subject: [PATCH] [IMP] point_of_sale: add patches from `posbox` branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit contains the patches from the now obsolete 'posbox' branch. These patches were written by Martin Donies (@mdo-odoo) and Frédéric Van der Essen (@fvdsn). --- addons/hw_escpos/controllers/main.py | 4 ++-- addons/hw_posbox_homepage/controllers/main.py | 2 +- addons/hw_posbox_upgrade/controllers/main.py | 10 ++++---- addons/hw_proxy/controllers/main.py | 18 +++++++++++++- addons/hw_scale/controllers/main.py | 24 ++++++++++++------- addons/hw_scanner/controllers/main.py | 4 ++++ 6 files changed, 46 insertions(+), 16 deletions(-) diff --git a/addons/hw_escpos/controllers/main.py b/addons/hw_escpos/controllers/main.py index c57238bd659..2ec0036af8d 100644 --- a/addons/hw_escpos/controllers/main.py +++ b/addons/hw_escpos/controllers/main.py @@ -146,7 +146,7 @@ class EscposDriver(Thread): _logger.warning('ESC/POS Device Disconnected: '+message) def run(self): - + printer = None if not escpos: _logger.error('ESC/POS cannot initialize, please verify system dependencies.') return @@ -192,7 +192,7 @@ class EscposDriver(Thread): errmsg = str(e) + '\n' + '-'*60+'\n' + traceback.format_exc() + '-'*60 + '\n' _logger.error(errmsg); finally: - if error: + if error: self.queue.put((timestamp, task, data)) if printer: printer.close() diff --git a/addons/hw_posbox_homepage/controllers/main.py b/addons/hw_posbox_homepage/controllers/main.py index 25e33c409fa..ad98b1f46a2 100644 --- a/addons/hw_posbox_homepage/controllers/main.py +++ b/addons/hw_posbox_homepage/controllers/main.py @@ -43,7 +43,7 @@ index_template = """ to the hardware status page

- The PosBox software installed on this posbox is version 6, + The PosBox software installed on this posbox is version 8, the posbox version number is independent from Odoo. You can upgrade the software on the upgrade page

diff --git a/addons/hw_posbox_upgrade/controllers/main.py b/addons/hw_posbox_upgrade/controllers/main.py index 0947fbc8564..52df1e8e245 100644 --- a/addons/hw_posbox_upgrade/controllers/main.py +++ b/addons/hw_posbox_upgrade/controllers/main.py @@ -73,9 +73,11 @@ upgrade_template = """

PosBox Software Upgrade

- This tool will help you perform an upgrade of the PosBox's software. + This tool will help you perform an upgrade of the PosBox's software over the + internet. +

However the preferred method to upgrade the posbox is to flash the sd-card with - the latest image. The upgrade + the latest image. The upgrade procedure is explained into to the PosBox manual

@@ -106,7 +108,7 @@ class PosboxUpgrader(hw_proxy.Proxy): self.upgrading.release() return 'UPTODATE' else: - os.system('/bin/bash /home/pi/openerp/update.sh') + os.system('/bin/bash /home/pi/odoo/posbox/update.sh') self.last_upgrade = time.time() self.upgrading.release() return 'SUCCESS' @@ -118,7 +120,7 @@ class PosboxUpgrader(hw_proxy.Proxy): self.upgrading.release() return 'RESTARTED' else: - os.system('/bin/bash /home/pi/openerp/restart.sh') + os.system('/bin/bash /home/pi/odoo/posbox/restart.sh') self.last_upgrade = time.time() self.upgrading.release() return 'SUCCESS' diff --git a/addons/hw_proxy/controllers/main.py b/addons/hw_proxy/controllers/main.py index eced1d65b94..677bff1354e 100644 --- a/addons/hw_proxy/controllers/main.py +++ b/addons/hw_proxy/controllers/main.py @@ -17,6 +17,14 @@ _logger = logging.getLogger(__name__) from openerp import http from openerp.http import request +# Those are the builtin raspberry pi USB modules, they should +# not appear in the list of connected devices. +BANNED_DEVICES = set([ + "0424:9514", # Standard Microsystem Corp. Builtin Ethernet module + "1d6b:0002", # Linux Foundation 2.0 root hub + "0424:ec00", # Standard Microsystem Corp. Other Builtin Ethernet module +]) + # drivers modules must add to drivers an object with a get_status() method # so that 'status' can return the status of all active drivers @@ -88,10 +96,18 @@ class Proxy(http.Controller):

The list of connected USB devices as seen by the posbox

""" devices = commands.getoutput("lsusb").split('\n') + count = 0 resp += "
\n" for device in devices: device_name = device[device.find('ID')+2:] - resp+= "
"+device_name+"
\n" + device_id = device_name.split()[0] + if not (device_id in BANNED_DEVICES): + resp+= "
"+device_name+"
\n" + count += 1 + + if count == 0: + resp += "
No USB Device Found
" + resp += "
\n" resp += """

Add New Printer

diff --git a/addons/hw_scale/controllers/main.py b/addons/hw_scale/controllers/main.py index 0c39ffcde9d..b03fbc0ae97 100644 --- a/addons/hw_scale/controllers/main.py +++ b/addons/hw_scale/controllers/main.py @@ -44,6 +44,11 @@ class Scale(Thread): if status == self.status['status']: if message != None and message != self.status['messages'][-1]: self.status['messages'].append(message) + + if status == 'error' and message: + _logger.error('Scale Error: '+message) + elif status == 'disconnected' and message: + _logger.warning('Disconnected Scale: '+message) else: self.status['status'] = status if message: @@ -51,13 +56,16 @@ class Scale(Thread): else: self.status['messages'] = [] - if status == 'error' and message: - _logger.error('Scale Error: '+message) - elif status == 'disconnected' and message: - _logger.warning('Disconnected Scale: '+message) + if status == 'error' and message: + _logger.error('Scale Error: '+message) + elif status == 'disconnected' and message: + _logger.warning('Disconnected Scale: '+message) def get_device(self): try: + if not os.path.exists(self.input_dir): + self.set_status('disconnected','Scale Not Found') + return None devices = [ device for device in listdir(self.input_dir)] scales = [ device for device in devices if ('mettler' in device.lower()) or ('toledo' in device.lower()) ] if len(scales) > 0: @@ -69,8 +77,8 @@ class Scale(Thread): stopbits = serial.STOPBITS_ONE, parity = serial.PARITY_EVEN, #xonxoff = serial.XON, - timeout = 0.01, - writeTimeout= 0.01) + timeout = 0.02, + writeTimeout= 0.02) else: self.set_status('disconnected','Scale Not Found') return None @@ -95,7 +103,7 @@ class Scale(Thread): if self.device: try: self.device.write('W') - time.sleep(0.1) + time.sleep(0.2) answer = [] while True: @@ -171,7 +179,7 @@ class Scale(Thread): while True: if self.device: self.read_weight() - time.sleep(0.05) + time.sleep(0.15) else: with self.scalelock: self.device = self.get_device() diff --git a/addons/hw_scanner/controllers/main.py b/addons/hw_scanner/controllers/main.py index 6e53c37006f..bcad8b92906 100644 --- a/addons/hw_scanner/controllers/main.py +++ b/addons/hw_scanner/controllers/main.py @@ -111,6 +111,8 @@ class Scanner(Thread): def get_device(self): try: + if not evdev: + return None devices = [ device for device in listdir(self.input_dir)] keyboards = [ device for device in devices if ('kbd' in device) and ('keyboard' not in device.lower())] scanners = [ device for device in devices if ('barcode' in device.lower()) or ('scanner' in device.lower())] @@ -133,6 +135,7 @@ class Scanner(Thread): been returned before. This is necessary to catch barcodes scanned while the POS is busy reading another barcode """ + self.lockedstart() while True: @@ -164,6 +167,7 @@ class Scanner(Thread): try: device.ungrab() except Exception as e: + device = None self.set_status('error',str(e)) else: time.sleep(5) # wait until a suitable device is plugged