From d13fb14f1ecec10f1308afccee3f69e1daa67e9f Mon Sep 17 00:00:00 2001 From: MOENS Alexandre Date: Tue, 5 Jun 2018 14:09:32 +0200 Subject: [PATCH] [REF] barcodes: pager: warn if a pager isn't present If a barcode triggering an action on the pager was scanned while a pager wasn't present in the page (see the workorder tablet view), a traceback happened. We display a warning instead. Task: 1831245 --- .../static/src/js/barcode_form_view.js | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/addons/barcodes/static/src/js/barcode_form_view.js b/addons/barcodes/static/src/js/barcode_form_view.js index 363f33606c3..525d0b84ebd 100644 --- a/addons/barcodes/static/src/js/barcode_form_view.js +++ b/addons/barcodes/static/src/js/barcode_form_view.js @@ -91,6 +91,10 @@ FormController.include({ _barcodePagerFirst: function () { var self = this; return this.mutex.exec(function () {}).then(function () { + if (!self.pager) { + self.do_warn(_t('Error: Pager not available')); + return; + } self.pager.updateState({ current_min: 1, }, {notifyChange: true}); @@ -102,6 +106,10 @@ FormController.include({ _barcodePagerLast: function () { var self = this; return this.mutex.exec(function () {}).then(function () { + if (!self.pager) { + self.do_warn(_t('Error: Pager not available')); + return; + } var state = self.model.get(self.handle, {raw: true}); self.pager.updateState({ current_min: state.count, @@ -112,13 +120,27 @@ FormController.include({ * @private */ _barcodePagerNext: function () { - return this.mutex.exec(function () {}).then(this.pager.next.bind(this.pager)); + var self = this; + return this.mutex.exec(function () {}).then(function () { + if (!self.pager) { + self.do_warn(_t('Error: Pager not available')); + return; + } + self.pager.next(); + }); }, /** * @private */ _barcodePagerPrevious: function () { - return this.mutex.exec(function () {}).then(this.pager.previous.bind(this.pager)); + var self = this; + return this.mutex.exec(function () {}).then(function () { + if (!self.pager) { + self.do_warn(_t('Error: Pager not available')); + return; + } + self.pager.previous(); + }); }, /** * Returns true iff the given barcode matches the given record (candidate).