summaryrefslogtreecommitdiff
path: root/addons/barcodes/static/src/js
diff options
context:
space:
mode:
authorPierre Masereel <pim@odoo.com>2016-10-10 16:51:58 +0200
committerPierre Masereel <pim@odoo.com>2016-10-14 12:22:22 +0200
commit852e2c557e3449db2f367fca69d9c6a778996ae4 (patch)
treec9ce1652c242706ba6b83d248e36dcf3195fa6ab /addons/barcodes/static/src/js
parent4a0a2794720834a2737259bb1d278d69015ab4c5 (diff)
[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
Diffstat (limited to 'addons/barcodes/static/src/js')
-rw-r--r--addons/barcodes/static/src/js/form_view_barcode_handler.js11
1 files changed, 8 insertions, 3 deletions
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;
+ }
},
});