From 587e90fe18900037055fde2086597f6957e30a22 Mon Sep 17 00:00:00 2001 From: Suraj Shukla Date: Tue, 26 Feb 2019 09:23:42 +0000 Subject: [FIX] web: reload form after failing save Let's assume a form view with a clickable statusbar, in readonly. When the user clicks on a status, the change is saved directly. When the save fails (e.g. access rights), the statusbar widget is in an inconsistent state and must be reloaded. This rev. reloads the whole record and re-render the form when this happens. Related to Issue: #1915391 closes #29519 Signed-off-by: Aaron Bohy (aab) Co-authored-by: Mohammed Shekha --- addons/web/static/src/js/views/field_manager_mixin.js | 15 +++++++++++++++ addons/web/static/src/js/views/form/form_controller.js | 13 +++++++++++++ 2 files changed, 28 insertions(+) (limited to 'addons/web/static/src/js/views') 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 2b38ca4403d..75793239979 100644 --- a/addons/web/static/src/js/views/field_manager_mixin.js +++ b/addons/web/static/src/js/views/field_manager_mixin.js @@ -52,6 +52,8 @@ var FieldManagerMixin = { if (event.data.force_save) { return self.model.save(dataPointID).then(function () { return self._confirmSave(dataPointID); + }).fail(function () { + return self._rejectSave(dataPointID); }); } else if (options.notifyChange !== false) { return self._confirmChange(dataPointID, result, event); @@ -84,6 +86,19 @@ var FieldManagerMixin = { _confirmSave: function (id) { return $.when(); }, + /** + * This method will be called whenever a save has been triggered by a change + * and has failed. For example, when a statusbar button is clicked in a + * readonly form view. + * + * @abstract + * @private + * @param {string} id The basicModel ID for the saved record + * @returns {Deferred} + */ + _rejectSave: function (id) { + return $.when(); + }, //-------------------------------------------------------------------------- // Handlers diff --git a/addons/web/static/src/js/views/form/form_controller.js b/addons/web/static/src/js/views/form/form_controller.js index 8e777c1acd9..2d66c293483 100644 --- a/addons/web/static/src/js/views/form/form_controller.js +++ b/addons/web/static/src/js/views/form/form_controller.js @@ -309,6 +309,19 @@ var FormController = BasicController.extend({ state.id = env.currentId; this._super(state); }, + /** + * Overrides to reload the form when saving failed in readonly (e.g. after + * a change on a widget like priority or statusbar). + * + * @override + * @private + */ + _rejectSave: function () { + if (this.mode === 'readonly') { + return this.reload(); + } + return this._super.apply(this, arguments); + }, /** * Calls unfreezeOrder when changing the mode. * -- cgit v1.2.3 From 6b676f62352ca133723bf9cc9bafa8d05728eb0e Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 8 Mar 2019 12:57:02 +0000 Subject: [FIX] web: record datapoint context without group_by or orderedBy Have a list view, apply a group_by and a filter with a sort parameter Click on one record to access the form view Have a x2m within it Before this commit, the x2m records were loaded with a context containing the keys orderedBy and group_by It seems harmless at first, but even conceptually those keys should not be here - they apply on a list of records, and not to individual ones - they may contain field names not existing in the x2m model Hence, when accessing another list view through an action button, the list will try to be orderedBy or group_by with the given context Which is plain wrong in the first place and may cause crashes After this commit, the context of a record datapoint (representing a single record) is stripped from the keys Read the opw for a concrete use case OPW 1943583 closes odoo/odoo#31706 Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/js/views/basic/basic_model.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/views') diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 1a6e21c4049..1a4f1574ac8 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -3295,6 +3295,7 @@ var BasicModel = AbstractModel.extend({ var res_id, value; var res_ids = params.res_ids || []; var data = params.data || (type === 'record' ? {} : []); + var context = params.context; if (type === 'record') { res_id = params.res_id || (params.data && params.data.id); if (res_id) { @@ -3302,6 +3303,9 @@ var BasicModel = AbstractModel.extend({ } else { res_id = _.uniqueId('virtual_'); } + // it doesn't make sense for a record datapoint to have those keys + // besides, it will mess up x2m and actions down the line + context = _.omit(context, ['orderedBy', 'group_by']); } else { var isValueArray = params.value instanceof Array; res_id = isValueArray ? params.value[0] : undefined; @@ -3319,7 +3323,7 @@ var BasicModel = AbstractModel.extend({ _domains: {}, _rawChanges: {}, aggregateValues: params.aggregateValues || {}, - context: params.context, + context: context, count: params.count || res_ids.length, data: data, domain: params.domain || [], -- cgit v1.2.3