[IMP] point_of_sale: add patches from `posbox` branch

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).
This commit is contained in:
Joren Van Onder 2015-08-11 12:55:27 +02:00 committed by Christophe Simonis
parent 0d3a9c47e7
commit 59b5f136bf
6 changed files with 46 additions and 16 deletions

View File

@ -146,7 +146,7 @@ class EscposDriver(Thread):
_logger.warning('ESC/POS Device Disconnected: '+message) _logger.warning('ESC/POS Device Disconnected: '+message)
def run(self): def run(self):
printer = None
if not escpos: if not escpos:
_logger.error('ESC/POS cannot initialize, please verify system dependencies.') _logger.error('ESC/POS cannot initialize, please verify system dependencies.')
return return
@ -192,7 +192,7 @@ class EscposDriver(Thread):
errmsg = str(e) + '\n' + '-'*60+'\n' + traceback.format_exc() + '-'*60 + '\n' errmsg = str(e) + '\n' + '-'*60+'\n' + traceback.format_exc() + '-'*60 + '\n'
_logger.error(errmsg); _logger.error(errmsg);
finally: finally:
if error: if error:
self.queue.put((timestamp, task, data)) self.queue.put((timestamp, task, data))
if printer: if printer:
printer.close() printer.close()

View File

@ -43,7 +43,7 @@ index_template = """
to the <a href='/hw_proxy/status'>hardware status page</a> to the <a href='/hw_proxy/status'>hardware status page</a>
</p> </p>
<p> <p>
The PosBox software installed on this posbox is <b>version 6</b>, The PosBox software installed on this posbox is <b>version 8</b>,
the posbox version number is independent from Odoo. You can upgrade the posbox version number is independent from Odoo. You can upgrade
the software on the <a href='/hw_proxy/upgrade/'>upgrade page</a> the software on the <a href='/hw_proxy/upgrade/'>upgrade page</a>
</p> </p>

View File

@ -73,9 +73,11 @@ upgrade_template = """
<body> <body>
<h1>PosBox Software Upgrade</h1> <h1>PosBox Software Upgrade</h1>
<p> <p>
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.
<p></p>
However the preferred method to upgrade the posbox is to flash the sd-card with However the preferred method to upgrade the posbox is to flash the sd-card with
the <a href='http://nightly.openerp.com/trunk/posbox/'>latest image</a>. The upgrade the <a href='http://nightly.odoo.com/trunk/posbox/'>latest image</a>. The upgrade
procedure is explained into to the <a href='/hw_proxy/static/doc/manual.pdf'>PosBox manual</a> procedure is explained into to the <a href='/hw_proxy/static/doc/manual.pdf'>PosBox manual</a>
</p> </p>
<p> <p>
@ -106,7 +108,7 @@ class PosboxUpgrader(hw_proxy.Proxy):
self.upgrading.release() self.upgrading.release()
return 'UPTODATE' return 'UPTODATE'
else: 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.last_upgrade = time.time()
self.upgrading.release() self.upgrading.release()
return 'SUCCESS' return 'SUCCESS'
@ -118,7 +120,7 @@ class PosboxUpgrader(hw_proxy.Proxy):
self.upgrading.release() self.upgrading.release()
return 'RESTARTED' return 'RESTARTED'
else: 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.last_upgrade = time.time()
self.upgrading.release() self.upgrading.release()
return 'SUCCESS' return 'SUCCESS'

View File

@ -17,6 +17,14 @@ _logger = logging.getLogger(__name__)
from openerp import http from openerp import http
from openerp.http import request 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 # drivers modules must add to drivers an object with a get_status() method
# so that 'status' can return the status of all active drivers # so that 'status' can return the status of all active drivers
@ -88,10 +96,18 @@ class Proxy(http.Controller):
<p>The list of connected USB devices as seen by the posbox</p> <p>The list of connected USB devices as seen by the posbox</p>
""" """
devices = commands.getoutput("lsusb").split('\n') devices = commands.getoutput("lsusb").split('\n')
count = 0
resp += "<div class='devices'>\n" resp += "<div class='devices'>\n"
for device in devices: for device in devices:
device_name = device[device.find('ID')+2:] device_name = device[device.find('ID')+2:]
resp+= "<div class='device' data-device='"+device+"'>"+device_name+"</div>\n" device_id = device_name.split()[0]
if not (device_id in BANNED_DEVICES):
resp+= "<div class='device' data-device='"+device+"'>"+device_name+"</div>\n"
count += 1
if count == 0:
resp += "<div class='device'>No USB Device Found</div>"
resp += "</div>\n" resp += "</div>\n"
resp += """ resp += """
<h2>Add New Printer</h2> <h2>Add New Printer</h2>

View File

@ -44,6 +44,11 @@ class Scale(Thread):
if status == self.status['status']: if status == self.status['status']:
if message != None and message != self.status['messages'][-1]: if message != None and message != self.status['messages'][-1]:
self.status['messages'].append(message) 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: else:
self.status['status'] = status self.status['status'] = status
if message: if message:
@ -51,13 +56,16 @@ class Scale(Thread):
else: else:
self.status['messages'] = [] self.status['messages'] = []
if status == 'error' and message: if status == 'error' and message:
_logger.error('Scale Error: '+message) _logger.error('Scale Error: '+message)
elif status == 'disconnected' and message: elif status == 'disconnected' and message:
_logger.warning('Disconnected Scale: '+message) _logger.warning('Disconnected Scale: '+message)
def get_device(self): def get_device(self):
try: 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)] 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()) ] scales = [ device for device in devices if ('mettler' in device.lower()) or ('toledo' in device.lower()) ]
if len(scales) > 0: if len(scales) > 0:
@ -69,8 +77,8 @@ class Scale(Thread):
stopbits = serial.STOPBITS_ONE, stopbits = serial.STOPBITS_ONE,
parity = serial.PARITY_EVEN, parity = serial.PARITY_EVEN,
#xonxoff = serial.XON, #xonxoff = serial.XON,
timeout = 0.01, timeout = 0.02,
writeTimeout= 0.01) writeTimeout= 0.02)
else: else:
self.set_status('disconnected','Scale Not Found') self.set_status('disconnected','Scale Not Found')
return None return None
@ -95,7 +103,7 @@ class Scale(Thread):
if self.device: if self.device:
try: try:
self.device.write('W') self.device.write('W')
time.sleep(0.1) time.sleep(0.2)
answer = [] answer = []
while True: while True:
@ -171,7 +179,7 @@ class Scale(Thread):
while True: while True:
if self.device: if self.device:
self.read_weight() self.read_weight()
time.sleep(0.05) time.sleep(0.15)
else: else:
with self.scalelock: with self.scalelock:
self.device = self.get_device() self.device = self.get_device()

View File

@ -111,6 +111,8 @@ class Scanner(Thread):
def get_device(self): def get_device(self):
try: try:
if not evdev:
return None
devices = [ device for device in listdir(self.input_dir)] 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())] 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())] 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 been returned before. This is necessary to catch barcodes scanned while the POS is
busy reading another barcode busy reading another barcode
""" """
self.lockedstart() self.lockedstart()
while True: while True:
@ -164,6 +167,7 @@ class Scanner(Thread):
try: try:
device.ungrab() device.ungrab()
except Exception as e: except Exception as e:
device = None
self.set_status('error',str(e)) self.set_status('error',str(e))
else: else:
time.sleep(5) # wait until a suitable device is plugged time.sleep(5) # wait until a suitable device is plugged