diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 8b62b5db398..ff347794f5e 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -659,6 +659,7 @@ class AccountInvoice(models.Model): am = line2[tmp]['debit'] - line2[tmp]['credit'] + (l['debit'] - l['credit']) line2[tmp]['debit'] = (am > 0) and am or 0.0 line2[tmp]['credit'] = (am < 0) and -am or 0.0 + line2[tmp]['amount_currency'] += l['amount_currency'] line2[tmp]['analytic_line_ids'] += l['analytic_line_ids'] else: line2[tmp] = l diff --git a/addons/base_geolocalize/__openerp__.py b/addons/base_geolocalize/__openerp__.py index d4fdf686a8c..ee65fc738b5 100644 --- a/addons/base_geolocalize/__openerp__.py +++ b/addons/base_geolocalize/__openerp__.py @@ -10,7 +10,7 @@ Partners geolocalization ======================== """, - 'depends': ['crm'], + 'depends': ['base'], 'demo': [ ], 'data': [ diff --git a/addons/hw_blackbox_be/controllers/main.py b/addons/hw_blackbox_be/controllers/main.py index fbc7664cbc0..8db84fbbffa 100644 --- a/addons/hw_blackbox_be/controllers/main.py +++ b/addons/hw_blackbox_be/controllers/main.py @@ -37,7 +37,7 @@ class Blackbox(Thread): # request. The first device to give an answer that makes sense # wins. def _find_device_path_by_probing(self): - path = "/dev/serial/by-id/" + path = "/dev/serial/by-path/" probe_message = self._wrap_low_level_message_around("S000") try: diff --git a/addons/hw_scale/controllers/main.py b/addons/hw_scale/controllers/main.py index 2f9e0271dd5..2437b7829ea 100644 --- a/addons/hw_scale/controllers/main.py +++ b/addons/hw_scale/controllers/main.py @@ -29,10 +29,12 @@ class Scale(Thread): self.lock = Lock() self.scalelock = Lock() self.status = {'status':'connecting', 'messages':[]} - self.input_dir = '/dev/serial/by-id/' + self.input_dir = '/dev/serial/by-path/' self.weight = 0 self.weight_info = 'ok' self.device = None + self.probed_device_paths = [] + self.path_to_scale = '' def lockedstart(self): with self.lock: @@ -61,27 +63,55 @@ class Scale(Thread): elif status == 'disconnected' and message: _logger.info('Disconnected Scale: %s', message) + def _get_raw_response(self, connection): + response = "" + while True: + byte = connection.read(1) + + if byte: + response += byte + else: + return response + 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: - print join(self.input_dir,scales[0]) - self.set_status('connected','Connected to '+scales[0]) - return serial.Serial(join(self.input_dir,scales[0]), - baudrate = 9600, - bytesize = serial.SEVENBITS, - stopbits = serial.STOPBITS_ONE, - parity = serial.PARITY_EVEN, - #xonxoff = serial.XON, - timeout = 0.02, - writeTimeout= 0.02) - else: - self.set_status('disconnected','Scale Not Found') - return None + + if len(devices) > 0: + for device in devices: + path = self.input_dir + device + + # don't keep probing devices that are not a scale, + # only keep probing if in the past the device was + # confirmed to be a scale + if path not in self.probed_device_paths or path == self.path_to_scale: + _logger.debug('Probing: ' + path) + connection = serial.Serial(path, + baudrate = 9600, + bytesize = serial.SEVENBITS, + stopbits = serial.STOPBITS_ONE, + parity = serial.PARITY_EVEN, + timeout = 1, + writeTimeout = 1) + + connection.write("W") + self.probed_device_paths.append(path) + + if self._get_raw_response(connection): + _logger.debug(path + ' is scale') + self.path_to_scale = path + self.set_status('connected','Connected to '+device) + connection.timeout = 0.02 + connection.writeTimeout = 0.02 + return connection + else: + _logger.debug('Already probed: ' + path) + + self.set_status('disconnected','Scale Not Found') + return None except Exception as e: self.set_status('error',str(e)) return None diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 66f88423aea..dd713175f13 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1444,7 +1444,9 @@ exports.Paymentline = Backbone.Model.extend({ return this.amount; }, get_amount_str: function(){ - return this.amount.toFixed(this.pos.currency.decimals); + return formats.format_value(this.amount, { + type: 'float', digits: [69, this.pos.currency.decimals] + }); }, set_selected: function(selected){ if(this.selected !== selected){ diff --git a/addons/report/controllers/main.py b/addons/report/controllers/main.py index 756aa8fb113..57e4eaab38b 100644 --- a/addons/report/controllers/main.py +++ b/addons/report/controllers/main.py @@ -66,12 +66,7 @@ class ReportController(Controller): at the bottom of the output image """ try: - width, height, humanreadable = int(width), int(height), bool(int(humanreadable)) - barcode = createBarcodeDrawing( - type, value=value, format='png', width=width, height=height, - humanReadable = humanreadable - ) - barcode = barcode.asString('png') + barcode = request.registry['report'].barcode(type, value, width=width, height=height, humanreadable=humanreadable) except (ValueError, AttributeError): raise exceptions.HTTPException(description='Cannot convert into barcode.') diff --git a/addons/report/models/__init__.py b/addons/report/models/__init__.py index f7f517bb1d2..895802e57d4 100644 --- a/addons/report/models/__init__.py +++ b/addons/report/models/__init__.py @@ -1,4 +1,5 @@ import report import report_paperformat import abstract_report +import ir_qweb import res_company diff --git a/addons/report/models/ir_qweb.py b/addons/report/models/ir_qweb.py new file mode 100644 index 00000000000..6e60f795c6b --- /dev/null +++ b/addons/report/models/ir_qweb.py @@ -0,0 +1,24 @@ +from reportlab.graphics.barcode import createBarcodeDrawing + +from openerp.osv import osv +from openerp.addons.base.ir.ir_qweb import HTMLSafe + + +class BarcodeConverter(osv.AbstractModel): + """ ``barcode`` widget rendering, inserts a data:uri-using image tag in the + document. May be overridden by e.g. the website module to generate links + instead. + """ + _name = 'ir.qweb.field.barcode' + _inherit = 'ir.qweb.field' + + def value_to_html(self, cr, uid, value, field, options=None, context=None): + barcode_type = options.get('type', 'Code128') + barcode = self.pool['report'].barcode( + barcode_type, + value, + **dict((key, value) for key, value in options.items() if key in ['width', 'height', 'humanreadable'])) + return HTMLSafe('' % ('png', barcode.encode('base64'))) + + def from_html(self, cr, uid, model, field, element, context=None): + return None diff --git a/addons/report/models/report.py b/addons/report/models/report.py index 694b240a327..ed93ed9344d 100644 --- a/addons/report/models/report.py +++ b/addons/report/models/report.py @@ -25,6 +25,7 @@ from contextlib import closing from distutils.version import LooseVersion from functools import partial from pyPdf import PdfFileWriter, PdfFileReader +from reportlab.graphics.barcode import createBarcodeDrawing #-------------------------------------------------------------------------- @@ -542,3 +543,18 @@ class Report(osv.Model): stream.close() return merged_file_path + + def barcode(self, barcode_type, value, width=600, height=100, humanreadable=0): + if barcode_type == 'UPCA' and len(value) in (11, 12, 13): + barcode_type = 'EAN13' + if len(value) in (11, 12): + value = '0%s' % value + try: + width, height, humanreadable = int(width), int(height), bool(int(humanreadable)) + barcode = createBarcodeDrawing( + barcode_type, value=value, format='png', width=width, height=height, + humanReadable=humanreadable + ) + return barcode.asString('png') + except (ValueError, AttributeError): + raise ValueError("Cannot convert into barcode.") diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 3321a6c2c23..a1aa25f5d2a 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -353,14 +353,22 @@ class website(osv.osv): if req is None: req = request.httprequest default = self.get_current_website(cr, uid, context=context).default_lang_code - uri = req.path - if req.query_string: - uri += '?' + req.query_string shorts = [] + + def get_url_localized(router, lang): + arguments = dict(request.endpoint_arguments) + for k, v in arguments.items(): + if isinstance(v, orm.browse_record): + arguments[k] = v.with_context(lang=lang) + return router.build(request.endpoint, arguments) + router = request.httprequest.app.get_db_router(request.db).bind('') for code, name in self.get_languages(cr, uid, ids, context=context): lg_path = ('/' + code) if code != default else '' lg = code.split('_') shorts.append(lg[0]) + uri = request.endpoint and get_url_localized(router, code) or request.httprequest.path + if req.query_string: + uri += '?' + req.query_string lang = { 'hreflang': ('-'.join(lg)).lower(), 'short': lg[0],