From 852e2c557e3449db2f367fca69d9c6a778996ae4 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Mon, 10 Oct 2016 16:51:58 +0200 Subject: [FIX] barcodes: set_quantity traceback on mobile When we are trying to set the quantity on a mobile device, we get a traceback saying that we cannot call the 'find' function on the elements returned by '_get_records'. This '_get_records' function returns a 'Collection' when called on a tree view and an 'Array' when called on a kanban view. When we are working on a mobile device, most of the one2many are displayed as kanban. The thing is when we work with the object returned by '_get_records' we call a 'find' method on it, which is implemented by Odoo's Collection class. So when we call 'find' on an 'Array' we actually call 'Array.prototype.find' which is implemented on most desktop browser and on some mobile browser [1]. This is what caused the traceback on Chrome in Android. To fix this issue, we enforce '_get_records' to always return an 'Array' and we ensure that, when working on this 'Array', we use '_.find'. [1] https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find --- addons/barcodes/static/src/js/form_view_barcode_handler.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'addons/barcodes/static/src/js/form_view_barcode_handler.js') diff --git a/addons/barcodes/static/src/js/form_view_barcode_handler.js b/addons/barcodes/static/src/js/form_view_barcode_handler.js index b00bce51c5e..ffc6dfc7383 100644 --- a/addons/barcodes/static/src/js/form_view_barcode_handler.js +++ b/addons/barcodes/static/src/js/form_view_barcode_handler.js @@ -81,7 +81,7 @@ var FormViewBarcodeHandler = common.AbstractField.extend(BarcodeHandlerMixin, { if (this.last_scanned_barcode) { var new_qty = window.prompt(_t('Set quantity'), character) || "0"; new_qty = new_qty.replace(',', '.'); - var record = this._get_records(field).find(function(record) { + var record = _.find(this._get_records(field), function (record) { return record.get('product_barcode') === self.last_scanned_barcode; }); if (record) { @@ -159,8 +159,13 @@ var FormViewBarcodeHandler = common.AbstractField.extend(BarcodeHandlerMixin, { }, _get_records: function(field) { - return field.viewmanager.active_view.controller.records || // tree view - field.viewmanager.active_view.controller.widgets; // kanban view + var active_view = field.viewmanager.active_view; + if (active_view.type === "kanban") { + return active_view.controller.widgets; + } else { + // tree view case + return active_view.controller.records.records; + } }, }); -- cgit v1.2.3