summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2019-09-30 09:57:21 +0000
committerJulien Mougenot <jum@odoo.com>2019-10-07 11:22:04 +0000
commitda2b24714616bfbaf3ed7834844618207ec6ca2c (patch)
treef21539e7c4d4bd7cfa7b958e959332710cf00346 /addons/web/static/src/js
parent0f412d56d6fa3f53e7a15b7eba87863334497cf0 (diff)
[FIX] web: m2o updates its value after reload
Changes the behaviour of many2ones when their value is changed via a form dialog. Before this commit, when editing a m2o with a form dialog opened by an external button, the field triggered an onchange with its old value before reloading its widget. This caused the edition in list views to display outdated information when saving multiple records. Now, the reload is executed first, then the onchange occurs so that the value is the newly updated one. Part of task 2078807 closes odoo/odoo#37576 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js9
-rw-r--r--addons/web/static/src/js/views/basic/basic_controller.js8
2 files changed, 13 insertions, 4 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index 3687c622039..2e14ee56e8d 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -726,8 +726,13 @@ var FieldMany2One = AbstractField.extend({
readonly: !self.can_write,
on_saved: function (record, changed) {
if (changed) {
- self._setValue(self.value.data, {forceChange: true}).then(function() {
- self.trigger_up('reload', {db_id: self.value.id});
+ const _setValue = self._setValue.bind(self, self.value.data, {
+ forceChange: true,
+ });
+ self.trigger_up('reload', {
+ db_id: self.value.id,
+ onSuccess: _setValue,
+ onFailure: _setValue,
});
}
},
diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js
index df1a03e0f42..7639d2dea99 100644
--- a/addons/web/static/src/js/views/basic/basic_controller.js
+++ b/addons/web/static/src/js/views/basic/basic_controller.js
@@ -705,21 +705,25 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
* re-render (reload the whole form by default)
* @param {string[]} [ev.data.fieldNames] list of the record's fields to
* reload
+ * @param {Function} [ev.data.onSuccess] callback executed after reload is resolved
+ * @param {Function} [ev.data.onFailure] callback executed when reload is rejected
*/
_onReload: function (ev) {
ev.stopPropagation(); // prevent other controllers from handling this request
var data = ev && ev.data || {};
var handle = data.db_id;
+ var prom;
if (handle) {
// reload the relational field given its db_id
- this.model.reload(handle).then(this._confirmSave.bind(this, handle));
+ prom = this.model.reload(handle).then(this._confirmSave.bind(this, handle));
} else {
// no db_id given, so reload the main record
- this.reload({
+ prom = this.reload({
fieldNames: data.fieldNames,
keepChanges: data.keepChanges || false,
});
}
+ prom.then(ev.data.onSuccess).guardedCatch(ev.data.onFailure);
},
/**
* Resequence records in the given order.