From 6df482eb99e83dbe3f6b51d950e70d8d7c5e4015 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 25 Aug 2017 16:13:57 +0200 Subject: [PATCH] [FIX] barcodes: barcode handlers should return a deferred This was the case about 15minutes ago. But before pushing we decided to change the Barcode override of FormController to directly use handlers of the FormController when it could (e.g. to handle 'Edit', 'Discard' actions). This wasn't a good idea as those handlers don't return anything, and the barcode mechanism requires its handlers to return a deferred. So basically, it crashed when such a barcode was scanned. Having a test suite is nice, but you should not forget to relaunch it before pushing... --- .../static/src/js/barcode_form_view.js | 109 ++++++++++-------- 1 file changed, 60 insertions(+), 49 deletions(-) diff --git a/addons/barcodes/static/src/js/barcode_form_view.js b/addons/barcodes/static/src/js/barcode_form_view.js index 5b042999bf6..3f1c5ef1a86 100644 --- a/addons/barcodes/static/src/js/barcode_form_view.js +++ b/addons/barcodes/static/src/js/barcode_form_view.js @@ -26,13 +26,13 @@ FormController.include({ this.activeBarcode = { form_view: { commands: { - 'O-CMD.EDIT': this._onEdit.bind(this), - 'O-CMD.CANCEL': this._onDiscard.bind(this), - 'O-CMD.SAVE': this._onCommandSave.bind(this), - 'O-CMD.PAGER-PREV': this._onCommandPrevious.bind(this), - 'O-CMD.PAGER-NEXT': this._onCommandNext.bind(this), - 'O-CMD.PAGER-FIRST': this._onCommandFirst.bind(this), - 'O-CMD.PAGER-LAST': this._onCommandLast.bind(this), + 'O-CMD.EDIT': this._barcodeEdit.bind(this), + 'O-CMD.CANCEL': this._barcodeDiscard.bind(this), + 'O-CMD.SAVE': this._barcodeSave.bind(this), + 'O-CMD.PAGER-PREV': this._barcodePagerPrevious.bind(this), + 'O-CMD.PAGER-NEXT': this._barcodePagerNext.bind(this), + 'O-CMD.PAGER-FIRST': this._barcodePagerFirst.bind(this), + 'O-CMD.PAGER-LAST': this._barcodePagerLast.bind(this), }, }, }; @@ -73,6 +73,53 @@ FormController.include({ return this._barcodeWithoutCandidate(record, barcode, activeBarcode); } }, + /** + * @private + */ + _barcodeDiscard: function () { + return this.discardChanges(); + }, + /** + * @private + */ + _barcodeEdit: function () { + return this._setMode('edit'); + }, + /** + * @private + */ + _barcodePagerFirst: function () { + var self = this; + return this.mutex.exec(function () {}).then(function () { + self.pager.updateState({ + current_min: 1, + }, {notifyChange: true}); + }); + }, + /** + * @private + */ + _barcodePagerLast: function () { + var self = this; + return this.mutex.exec(function () {}).then(function () { + var state = self.model.get(self.handle, {raw: true}); + self.pager.updateState({ + current_min: state.count, + }, {notifyChange: true}); + }); + }, + /** + * @private + */ + _barcodePagerNext: function () { + return this.mutex.exec(function () {}).then(this.pager.next.bind(this.pager)); + }, + /** + * @private + */ + _barcodePagerPrevious: function () { + return this.mutex.exec(function () {}).then(this.pager.previous.bind(this.pager)); + }, /** * Returns true iff the given barcode matches the given record (candidate). * @@ -85,6 +132,12 @@ FormController.include({ _barcodeRecordFilter: function (candidate, barcode, activeBarcode) { return candidate.data.product_barcode === barcode; }, + /** + * @private + */ + _barcodeSave: function () { + return this.saveRecord(); + }, /** * @private * @param {Object} candidate: record in the x2m @@ -111,7 +164,6 @@ FormController.include({ core.bus.on('barcode_scanned', this, this._barcodeScanned); core.bus.on('keypress', this, this._quantityListener); }, - /** * @private */ @@ -258,47 +310,6 @@ FormController.include({ }); }); }, - /** - * @private - */ - _onCommandFirst: function () { - var self = this; - return this.mutex.exec(function () {}).then(function () { - self.pager.updateState({ - current_min: 1, - }, {notifyChange: true}); - }); - }, - /** - * @private - */ - _onCommandLast: function () { - var self = this; - return this.mutex.exec(function () {}).then(function () { - var state = self.model.get(self.handle, {raw: true}); - self.pager.updateState({ - current_min: state.count, - }, {notifyChange: true}); - }); - }, - /** - * @private - */ - _onCommandNext: function () { - return this.mutex.exec(function () {}).then(this.pager.next.bind(this.pager)); - }, - /** - * @private - */ - _onCommandPrevious: function () { - return this.mutex.exec(function () {}).then(this.pager.previous.bind(this.pager)); - }, - /** - * @private - */ - _onCommandSave: function () { - return this.saveRecord(); - }, /** * @private * @param {KeyEvent} event