From e5305ca8b718ffec27474e57d06fb54340c81707 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Thu, 12 Apr 2018 14:20:24 +0200 Subject: [FIX] barcode: use the same process for quantity listener The barcode scanner and the quantity listener do not use the same proccess although they act for the same operation. (For example the quantity listener trigger onchange server side while the barcode scanner not if 'notifychange' key on the active_barcode is set to False) Since quantity listener is based on candidate we could directly call the _barcodeSelectedCandidate method in order to have a common behavior and code. --- addons/barcodes/static/src/js/barcode_form_view.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'addons/barcodes/static/src/js/barcode_form_view.js') diff --git a/addons/barcodes/static/src/js/barcode_form_view.js b/addons/barcodes/static/src/js/barcode_form_view.js index 1730b42290e..b5cad7a1509 100644 --- a/addons/barcodes/static/src/js/barcode_form_view.js +++ b/addons/barcodes/static/src/js/barcode_form_view.js @@ -146,10 +146,10 @@ FormController.include({ * @param {Object} activeBarcode: options sent by the field who use barcode features * @returns {Deferred} */ - _barcodeSelectedCandidate: function (candidate, record, barcode, activeBarcode) { + _barcodeSelectedCandidate: function (candidate, record, barcode, activeBarcode, quantity) { var changes = {}; var candidateChanges = {}; - candidateChanges[activeBarcode.quantity] = candidate.data[activeBarcode.quantity] + 1; + candidateChanges[activeBarcode.quantity] = quantity ? quantity : candidate.data[activeBarcode.quantity] + 1; changes[activeBarcode.fieldName] = { operation: 'UPDATE', id: candidate.id, @@ -306,6 +306,8 @@ FormController.include({ } return self.alive($.when.apply($, defs)).then(function () { if (!prefixed) { + // remember the barcode scanned for the quantity listener + self.current_barcode = barcode; // redraw the view if we scanned a real barcode (required if // we manually apply the change in JS, e.g. incrementing the // quantity) @@ -355,9 +357,10 @@ FormController.include({ title: _t('Set quantity'), buttons: [{text: _t('Select'), classes: 'btn-primary', close: true, click: function () { var new_qty = this.$content.find('.o_set_qty_input').val(); - var values = {}; - values[activeBarcode.quantity] = parseFloat(new_qty); - return self.model.notifyChanges(activeBarcode.candidate.id, values).then(function () { + var record = self.model.get(self.handle); + return self._barcodeSelectedCandidate(activeBarcode.candidate, record, + self.current_barcode, activeBarcode, parseFloat(new_qty)) + .then(function () { self.update({}, {reload: false}); }); }}, {text: _t('Discard'), close: true}], -- cgit v1.2.3 From a6e2830631be5b933c33bf7105aafc33e08665d5 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Thu, 12 Apr 2018 15:20:17 +0200 Subject: [FIX] barcode: do not trigger barcode on pending views The check on the event target and the barcode target is done outside the check on barcode found. That result in a warning for each modal/form view that is pending. This commit do the check before doing any operations in order to directly stop if the event target is not similiar to listening barcode target --- addons/barcodes/static/src/js/barcode_form_view.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'addons/barcodes/static/src/js/barcode_form_view.js') diff --git a/addons/barcodes/static/src/js/barcode_form_view.js b/addons/barcodes/static/src/js/barcode_form_view.js index b5cad7a1509..015119c5830 100644 --- a/addons/barcodes/static/src/js/barcode_form_view.js +++ b/addons/barcodes/static/src/js/barcode_form_view.js @@ -283,15 +283,14 @@ FormController.include({ function (reserved) {return barcode.indexOf(reserved) === 0;}); var hasCommand = false; var defs = []; + if (! $.contains(target, self.el)) { + return; + } for (var k in self.activeBarcode) { var activeBarcode = self.activeBarcode[k]; // 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)) { - continue; - } - var methods = self.activeBarcode[k].commands; var method = prefixed ? methods[barcode] : methods.barcode; if (method) { @@ -323,6 +322,9 @@ FormController.include({ _quantityListener: function (event) { var character = String.fromCharCode(event.which); + if (! $.contains(event.target, this.el)) { + return; + } // only catch the event if we're not focused in // another field and it's a number if (!$(event.target).is('body, .modal') || !/[0-9]/.test(character)) { -- cgit v1.2.3