diff options
| author | Vincent Schippefilt <vsc@odoo.com> | 2019-03-06 14:01:56 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2019-03-06 20:07:17 +0100 |
| commit | 0ab6a629978f2ce07cf9f03696a941a85da3f684 (patch) | |
| tree | 26f65ebf4f24776aa99c0afa7556a61e2abf6191 /addons/barcodes/static/src/js | |
| parent | d5a1ff3f64ec3a5f446f5ae5283526e32c3fc413 (diff) | |
[REF] barcodes: adapt code after jQuery update
Part of task 1896658
Co-authored-by: Aaron Bohy <aab@odoo.com>
Co-authored-by: Christophe Matthieu <chm@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Co-authored-by: David Monjoie <dmo@odoo.com>
Co-authored-by: Martin Geubelle <mge@odoo.com>
Co-authored-by: svs-odoo <svs@odoo.com>
Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
Diffstat (limited to 'addons/barcodes/static/src/js')
| -rw-r--r-- | addons/barcodes/static/src/js/barcode_events.js | 6 | ||||
| -rw-r--r-- | addons/barcodes/static/src/js/barcode_field.js | 6 | ||||
| -rw-r--r-- | addons/barcodes/static/src/js/barcode_form_view.js | 47 | ||||
| -rw-r--r-- | addons/barcodes/static/src/js/barcode_parser.js | 12 |
4 files changed, 35 insertions, 36 deletions
diff --git a/addons/barcodes/static/src/js/barcode_events.js b/addons/barcodes/static/src/js/barcode_events.js index bb28a8e1085..22c23ece8c3 100644 --- a/addons/barcodes/static/src/js/barcode_events.js +++ b/addons/barcodes/static/src/js/barcode_events.js @@ -289,9 +289,9 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, { }, stop: function(){ - $('body').unbind("keypress", this.__handler); - $('body').unbind("keydown", this.__keydown_handler); - $('body').unbind('keyup', this.__keyup_handler); + $('body').off("keypress", this.__handler); + $('body').off("keydown", this.__keydown_handler); + $('body').off('keyup', this.__keyup_handler); }, }); diff --git a/addons/barcodes/static/src/js/barcode_field.js b/addons/barcodes/static/src/js/barcode_field.js index d8a7a1c853e..b5786f8a161 100644 --- a/addons/barcodes/static/src/js/barcode_field.js +++ b/addons/barcodes/static/src/js/barcode_field.js @@ -13,7 +13,7 @@ var FieldFloatScannable = basicFields.FieldFloat.extend({ // The barcode_events component intercepts keypresses and releases them when it // appears they are not part of a barcode. But since released keypresses don't // trigger native behaviour (like characters input), we must simulate it. - 'keypress': '_onKeypress', + keypress: '_onKeypress', }), //-------------------------------------------------------------------------- @@ -24,9 +24,9 @@ var FieldFloatScannable = basicFields.FieldFloat.extend({ * @override * @private */ - _renderEdit: function() { + _renderEdit: function () { var self = this; - $.when(this._super()).then(function () { + return Promise.resolve(this._super()).then(function () { self.$input.data('enableBarcode', true); }); }, diff --git a/addons/barcodes/static/src/js/barcode_form_view.js b/addons/barcodes/static/src/js/barcode_form_view.js index 15e27498f94..08463f2b997 100644 --- a/addons/barcodes/static/src/js/barcode_form_view.js +++ b/addons/barcodes/static/src/js/barcode_form_view.js @@ -56,13 +56,13 @@ FormController.include({ * @private * @param {string} barcode sent by the scanner (string generate from keypress series) * @param {Object} activeBarcode: options sent by the field who use barcode features - * @returns {Deferred} + * @returns {Promise} */ _barcodeAddX2MQuantity: function (barcode, activeBarcode) { if (this.mode === 'readonly') { this.do_warn(_t('Error: Document not editable'), _t('To modify this document, please first start edition.')); - return new $.Deferred().reject(); + return Promise.reject(); } var record = this.model.get(this.handle); @@ -166,7 +166,7 @@ FormController.include({ * @param {Object} current record * @param {string} barcode sent by the scanner (string generate from keypress series) * @param {Object} activeBarcode: options sent by the field who use barcode features - * @returns {Deferred} + * @returns {Promise} */ _barcodeSelectedCandidate: function (candidate, record, barcode, activeBarcode, quantity) { var changes = {}; @@ -198,7 +198,7 @@ FormController.include({ * @param {Object} current record * @param {string} barcode sent by the scanner (string generate from keypress series) * @param {Object} activeBarcode: options sent by the field who use barcode features - * @returns {Deferred} + * @returns {Promise} */ _barcodeWithoutCandidate: function (record, barcode, activeBarcode) { var changes = {}; @@ -267,26 +267,25 @@ FormController.include({ * @param {string|function} method defined by the commands options * @param {string} barcode sent by the scanner (string generate from keypress series) * @param {Object} activeBarcode: options sent by the field who use barcode features - * @returns {Deferred} + * @returns {Promise} */ _barcodeActiveScanned: function (method, barcode, activeBarcode) { var self = this; var methodDef; - var def = new $.Deferred(); - if (typeof method === 'string') { - methodDef = this[method](barcode, activeBarcode); - } else { - methodDef = method.call(this, barcode, activeBarcode); - } - methodDef - .done(function () { - var record = self.model.get(self.handle); - var candidate = self._getBarCodeRecord(record, barcode, activeBarcode); - activeBarcode.candidate = candidate; - }) - .always(function () { - def.resolve(); - }); + var def = new Promise(function (resolve, reject) { + if (typeof method === 'string') { + methodDef = self[method](barcode, activeBarcode); + } else { + methodDef = method.call(self, barcode, activeBarcode); + } + methodDef + .then(function () { + var record = self.model.get(self.handle); + var candidate = self._getBarCodeRecord(record, barcode, activeBarcode); + activeBarcode.candidate = candidate; + }) + .then(resolve, resolve); + }); return def; }, /** @@ -296,7 +295,7 @@ FormController.include({ * @private * @param {string} barcode sent by the scanner (string generate from keypress series) * @param {DOM Object} target - * @returns {Deferred} + * @returns {Promise} */ _barcodeScanned: function (barcode, target) { var self = this; @@ -325,7 +324,7 @@ FormController.include({ if (prefixed && !hasCommand) { self.do_warn(_t('Error: Barcode command is undefined'), barcode); } - return self.alive($.when.apply($, defs)).then(function () { + return self.alive(Promise.all(defs)).then(function () { if (!prefixed) { // remember the barcode scanned for the quantity listener self.current_barcode = barcode; @@ -421,12 +420,12 @@ FormRenderer.include({ */ _barcodeButtonHandler: function ($button, node) { var commands = {}; - commands.barcode = function () {return $.when();}; + commands.barcode = function () {return Promise.resolve();}; commands['O-BTN.' + node.attrs.barcode_trigger] = function () { if (!$button.hasClass('o_invisible_modifier')) { $button.click(); } - return $.when(); + return Promise.resolve(); }; var name = node.attrs.name; if (node.attrs.string) { diff --git a/addons/barcodes/static/src/js/barcode_parser.js b/addons/barcodes/static/src/js/barcode_parser.js index cf357a438b2..3077f650fae 100644 --- a/addons/barcodes/static/src/js/barcode_parser.js +++ b/addons/barcodes/static/src/js/barcode_parser.js @@ -22,7 +22,7 @@ var BarcodeParser = Class.extend({ return; } var id = this.nomenclature_id[0]; - rpc.query({ + return rpc.query({ model: 'barcode.nomenclature', method: 'read', args: [[id], ['name','rule_ids','upc_ean_conv']], @@ -80,7 +80,7 @@ var BarcodeParser = Class.extend({ var total = sum1 + 3 * sum2; return Number((10 - total % 10) % 10); }, - + // returns true if the ean is a valid EAN barcode number by checking the control digit. // ean must be a string @@ -185,10 +185,10 @@ var BarcodeParser = Class.extend({ return match; }, - + // attempts to interpret a barcode (string encoding a barcode Code-128) // it will return an object containing various information about the barcode. - // most importantly : + // most importantly : // - code : the barcode // - type : the type of the barcode (e.g. alias, unit product, weighted product...) // @@ -198,7 +198,7 @@ var BarcodeParser = Class.extend({ parse_barcode: function(barcode){ var parsed_result = { encoding: '', - type:'error', + type:'error', code:barcode, base_code: barcode, value: 0, @@ -213,7 +213,7 @@ var BarcodeParser = Class.extend({ var rule = rules[i]; var cur_barcode = barcode; - if ( rule.encoding === 'ean13' && + if ( rule.encoding === 'ean13' && this.check_encoding(barcode,'upca') && this.nomenclature.upc_ean_conv in {'upc2ean':'','always':''} ){ cur_barcode = '0' + cur_barcode; |
