[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)
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()

View File

@ -43,7 +43,7 @@ index_template = """
to the <a href='/hw_proxy/status'>hardware status page</a>
</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 software on the <a href='/hw_proxy/upgrade/'>upgrade page</a>
</p>

View File

@ -73,9 +73,11 @@ upgrade_template = """
<body>
<h1>PosBox Software Upgrade</h1>
<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
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>
</p>
<p>
@ -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'

View File

@ -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):
<p>The list of connected USB devices as seen by the posbox</p>
"""
devices = commands.getoutput("lsusb").split('\n')
count = 0
resp += "<div class='devices'>\n"
for device in devices:
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 += """
<h2>Add New Printer</h2>

View File

@ -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()

View File

@ -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