summaryrefslogtreecommitdiff
path: root/addons/barcodes/static/src/js/form_view_barcode_handler.js
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2017-01-10 12:07:44 +0100
committerChristophe Simonis <chs@odoo.com>2017-01-10 12:07:44 +0100
commitf1583504cebe0d0fb87ccfe24773f9280770864d (patch)
tree7bf3d9cfe56a0a9207c00c8dc48bd6805763ace0 /addons/barcodes/static/src/js/form_view_barcode_handler.js
parent9073ecb6f59e1834bdd5e1aed96d6be4b03b00d5 (diff)
parent3f7b1f608344fed2f79d08ec602a700ec34c70cb (diff)
[MERGE] forward port branch 9.0 up to 3f7b1f60834
Diffstat (limited to 'addons/barcodes/static/src/js/form_view_barcode_handler.js')
-rw-r--r--addons/barcodes/static/src/js/form_view_barcode_handler.js48
1 files changed, 30 insertions, 18 deletions
diff --git a/addons/barcodes/static/src/js/form_view_barcode_handler.js b/addons/barcodes/static/src/js/form_view_barcode_handler.js
index ffc6dfc7383..fd0a84166f5 100644
--- a/addons/barcodes/static/src/js/form_view_barcode_handler.js
+++ b/addons/barcodes/static/src/js/form_view_barcode_handler.js
@@ -27,6 +27,8 @@ var FormViewBarcodeHandler = common.AbstractField.extend(BarcodeHandlerMixin, {
this.__quantity_listener = _.bind(this._set_quantity_listener, this);
BarcodeHandlerMixin.init.apply(this, arguments);
+ this.process_barcode_mutex = new utils.Mutex();
+
return this._super.apply(this, arguments);
},
@@ -136,25 +138,35 @@ var FormViewBarcodeHandler = common.AbstractField.extend(BarcodeHandlerMixin, {
else if (this.form_view.get('actual_mode') === 'view')
this._display_no_edit_mode_warning();
else {
- // Call hook method possibly implemented by subclass
- this.pre_onchange_hook(barcode).then(function(proceed) {
- if (proceed === true) {
- // Wait for hypothetical ongoing onchange to finish
- self.form_view.onchanges_mutex.exec(function() {
- // A real onchange is triggered when a value actually changes (which can correspond
- // to a widget's blur event per example). Commit the value of fields before
- // programmatically triggering an onchange to be consistent with this.
- var mutex_commit_value = new utils.Mutex();
- _.each(self.form_view.fields, function(field) {
- mutex_commit_value.exec(_.bind(field.commit_value, field));
- });
- return mutex_commit_value.def.then(function(){
- // Trigger the barcode onchange
- self.set_value(barcode);
- });
- });
+ var process_barcode = function () {
+ // this function can be passed to `Mutex.exec` in order to make sure
+ // that every ongoing onchanges in the form view are done
+ var form_onchanges_mutex = function () {
+ return self.form_view.onchanges_mutex.def;
}
- });
+
+ // before setting the barcode field with the received barcode, we commit
+ // every fields of the form view and we wait for their hypothetical ongoing
+ // onchanges to finish
+ var commit_mutex = new utils.Mutex();
+ _.each(self.form_view.fields, function (field) {
+ commit_mutex.exec(function () {
+ return field.commit_value();
+ });
+ commit_mutex.exec(form_onchanges_mutex);
+ });
+
+ return commit_mutex.def.then(function () {
+ return self.pre_onchange_hook(barcode).then(function (proceed) {
+ if (proceed) {
+ self.set_value(barcode); // set the barcode field with the received one
+ return form_onchanges_mutex(); // wait for its onchange to finish
+ }
+ });
+ });
+ };
+
+ this.process_barcode_mutex.exec(process_barcode);
}
},