summaryrefslogtreecommitdiff
path: root/addons/barcodes/static/src/js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-08-25 16:13:57 +0200
committerAaron Bohy <aab@odoo.com>2017-08-25 16:13:57 +0200
commit6df482eb99e83dbe3f6b51d950e70d8d7c5e4015 (patch)
treeec8a626cfa972913823a2033b8d1b0fcc29c62d4 /addons/barcodes/static/src/js
parent802dde31f3b58b8f26d6f6c584e5e4f8f392a482 (diff)
[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...
Diffstat (limited to 'addons/barcodes/static/src/js')
-rw-r--r--addons/barcodes/static/src/js/barcode_form_view.js109
1 files 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),
},
},
};
@@ -74,6 +74,53 @@ FormController.include({
}
},
/**
+ * @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).
*
* @private
@@ -87,6 +134,12 @@ FormController.include({
},
/**
* @private
+ */
+ _barcodeSave: function () {
+ return this.saveRecord();
+ },
+ /**
+ * @private
* @param {Object} candidate: record in the x2m
* @param {Object} current record
* @param {string} barcode sent by the scanner (string generate from keypress series)
@@ -111,7 +164,6 @@ FormController.include({
core.bus.on('barcode_scanned', this, this._barcodeScanned);
core.bus.on('keypress', this, this._quantityListener);
},
-
/**
* @private
*/
@@ -260,47 +312,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
*/
_quantityListener: function (event) {