summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/field_manager_mixin.js
diff options
context:
space:
mode:
authorMartin Geubelle <mge@odoo.com>2017-08-01 17:55:24 +0200
committerMartin Geubelle <mge@odoo.com>2017-08-02 08:49:12 +0200
commit211961c3747b5948e80ad8eb6f097636bc61b46d (patch)
tree81f5505c3893cf28301183f19a63c21ee953d1f4 /addons/web/static/src/js/views/field_manager_mixin.js
parent8d89148d1323b29fb97452ede3233e92b4a361e1 (diff)
[FIX] web: handle `mutexify` in standalone widgets
The rev. https://github.com/odoo/odoo/commit/99ae418bf24171fbc6bb27584059c27efb857e77 introduced a trigger_up `mutexify` when quick creating a record in a many2one ; this broke the behaviour when the many2one was standalone (because it has no BasicController and mutexify is handled in the latter). An attempt to fix this issue has been made in the rev. https://github.com/odoo/odoo/commit/e83c3e2678500c9bf2c17b4d23ae9a294ebafaa7 by adding an option `standalone` in the field widget options. In this case, the action was directly executed instead of the trigger_up. While this correctly works, this implies that the option needs to be added in every standalone many2one (and only many2one as the others won't use the option), which is not very convenient. An other attempt is made in this rev. by moving the mutexify handler from the BasicController to the FieldManagerMixin ; as a widget that instantiates a field widget needs to extend this mixin, both cases will work and we won't need to specify the option anymore. This commit thus partially reverts the rev. https://github.com/odoo/odoo/commit/e83c3e2678500c9bf2c17b4d23ae9a294ebafaa7
Diffstat (limited to 'addons/web/static/src/js/views/field_manager_mixin.js')
-rw-r--r--addons/web/static/src/js/views/field_manager_mixin.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/field_manager_mixin.js b/addons/web/static/src/js/views/field_manager_mixin.js
index b4bf1ddbf94..1ee7bf4a501 100644
--- a/addons/web/static/src/js/views/field_manager_mixin.js
+++ b/addons/web/static/src/js/views/field_manager_mixin.js
@@ -9,11 +9,13 @@ odoo.define('web.FieldManagerMixin', function (require) {
*/
var BasicModel = require('web.BasicModel');
+var concurrency = require('web.concurrency');
var FieldManagerMixin = {
custom_events: {
field_changed: '_onFieldChanged',
load: '_onLoad',
+ mutexify: '_onMutexify',
},
/**
* A FieldManagerMixin can be initialized with an instance of a basicModel.
@@ -23,6 +25,7 @@ var FieldManagerMixin = {
*/
init: function (model) {
this.model = model || new BasicModel(this);
+ this.mutex = new concurrency.Mutex();
},
//--------------------------------------------------------------------------
@@ -130,6 +133,15 @@ var FieldManagerMixin = {
data.on_success(self.model.get(db_id));
});
},
+ /**
+ * @private
+ * @param {OdooEvent} ev
+ * @param {function} ev.data.action the function to execute in the mutex
+ */
+ _onMutexify: function (ev) {
+ ev.stopPropagation(); // prevent other field managers from handling this request
+ this.mutex.exec(ev.data.action);
+ },
};
return FieldManagerMixin;