summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-05-31 08:29:00 +0200
committerAaron Bohy <aab@odoo.com>2017-05-31 20:53:55 +0200
commit23613b411feb6571c0f2907d8c88a7e8f8e39d87 (patch)
tree95a48c63e3b7c73d1a3239d278775c177bc1376c /addons/web/static/src/js/fields
parent5ff7199562132ccefd69ce84ce0c2c2984a40e26 (diff)
[FIX] web: x2m editable list: wait for onchanges
... before saving a line. Suppose that we have an editable list with one required field (e.g. many2one) with an onchange. We add a record and select a value for the many2one. Before the onchange returns, we click again on 'Add an item'. If we don't wait for the onchange to return before unselecting the row (i.e. before saving it), a confirm dialog asking if the changes can be discarded opens, because the line isn't valid yet. This could easily be reproduced on the sale_order form view, with some throttling. This rev. ensures that we wait for the onchange to return before saving the line, and thus before creating a new line.
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js21
1 files changed, 18 insertions, 3 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index c72c6cd3e79..f223fca68a4 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -873,15 +873,30 @@ var FieldX2Many = AbstractField.extend({
* changes; if the row could be saved, we make the row readonly. Otherwise,
* we trigger a new event for the view to tell it to discard the changes
* made to that row.
+ * Note that we do that in the controller mutex to ensure that the check on
+ * the row (whether or not it can be saved) is done once all potential
+ * onchange RPCs are done (those RPCs being executed in the same mutex).
+ * This particular handling is done in this handler, instead of in the
+ * _saveLine function directly, because _saveLine is also called from
+ * the controller (via commitChanges), and in this case, it is already
+ * executed in the mutex.
*
* @private
* @param {OdooEvent} ev
+ * @param {string} ev.recordID
+ * @param {function} ev.onSuccess success callback (see '_saveLine')
+ * @param {function} ev.onFailure fail callback (see '_saveLine')
*/
_onSaveLine: function (ev) {
+ var self = this;
ev.stopPropagation();
- this._saveLine(ev.data.recordID)
- .done(ev.data.onSuccess)
- .fail(ev.data.onFailure);
+ this.trigger_up('mutexify', {
+ action: function () {
+ return self._saveLine(ev.data.recordID)
+ .done(ev.data.onSuccess)
+ .fail(ev.data.onFailure);
+ },
+ });
},
/**
* Adds field name information to the event, so that the view upstream is