[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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user