diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2016-06-15 14:05:35 +0200 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2016-06-15 15:11:41 +0200 |
| commit | 0d19ee989d1d890860adaf360de204eb543136a5 (patch) | |
| tree | 31b4c4180818e2fdfcfd63351f0b9ebccaabc104 /addons/barcodes/static/src/js/barcode_handler_mixin.js | |
| parent | 972efbc0d11ab11cf2397e1a50b164833f562cee (diff) | |
[FIX] barcodes: manage several barcode widgets
In some cases, several barcode widgets can be found on the same page.
This is for example the case of the stock picking: there is a widget on
the `stock.picking` model (main view) itself, and a widget on the
`stock.pack.operation` model (modal view).
In this case, when the focus is not set directly on the field which
needs to be filled in, both widgets will trigger a `barcode_scanned`
scanned event. This will call the `on_barcode_scanned` Python method
which can lead to errors/warning. For example, the `on_barcode_scanned`
method on the `stock.picking` model raises a warning in case the barcode
scanned does not match any product/package.
The fix is to make sure that the event target is located in the correct
DOM element.
opw-677506
Diffstat (limited to 'addons/barcodes/static/src/js/barcode_handler_mixin.js')
| -rw-r--r-- | addons/barcodes/static/src/js/barcode_handler_mixin.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/addons/barcodes/static/src/js/barcode_handler_mixin.js b/addons/barcodes/static/src/js/barcode_handler_mixin.js index 5b01516788f..0a9480a979f 100644 --- a/addons/barcodes/static/src/js/barcode_handler_mixin.js +++ b/addons/barcodes/static/src/js/barcode_handler_mixin.js @@ -13,8 +13,13 @@ return { init: function() { var self = this; this._super.apply(this, arguments); - this.__on_barcode_scanned = function () { - self.on_barcode_scanned.apply(self, arguments); + this.__on_barcode_scanned = function (barcode, target) { + // Handle the case where there are several barcode widgets on the same page. Since the + // event is global on the page, all barcode widgets will be triggered. However, we only + // want to keep the event on the target widget. + if ($.contains(target, self.el)) { + self.on_barcode_scanned.call(self, barcode); + } }; this.start_listening(); // Handlers inside a View managed by a ViewManager only listen to barcode events while their view is displayed |
