From f896afcc8a54eae3efcdf034e3fd256942f7fa78 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Tue, 2 Jul 2019 10:41:19 +0200 Subject: [FIX] web: Call 'toggle_active' instead of 'write' Purpose ======= Currently when clicking on 'Archive' or 'Unarchive' on the list view, we write directly on the record {'active': False}, instead of calling toggle_active. Missing that way implementation of numerous business cases. Example - Archive a record --> archive its next activities - (Un)Archive a user --> (Un)Archive its partner - (Un)Archive a product variant --> (Un)Archive its template if there is only one variant - Archive an employee --> Open a wizard to choose an exit plan + describe the departure reason - Archive a route --> Archive its procurement rules - ... Specification ============= - Call toggle_active instead of write when calling toggleActive in the web client. - On the other hand, use actionArchive and actionUnarchive to apply the toggle action on the related records only. --- .../web/static/src/js/views/basic/basic_model.js | 54 ++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') 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 60c2f6a3314..311b0ee6947 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1176,7 +1176,7 @@ var BasicModel = AbstractModel.extend({ * @param {string} parentID id of the parent resource to reload * @returns {Promise} resolves to the parent id */ - toggleActive: function (recordIDs, value, parentID) { + toggleActive: function (recordIDs, parentID) { var self = this; var parent = this.localData[parentID]; var resIDs = _.map(recordIDs, function (recordID) { @@ -1184,8 +1184,56 @@ var BasicModel = AbstractModel.extend({ }); return this._rpc({ model: parent.model, - method: 'write', - args: [resIDs, { active: value }], + method: 'toggle_active', + args: [resIDs], + }) + .then(function () { + // optionally clear the DataManager's cache + self._invalidateCache(parent); + return self.reload(parentID); + }); + }, + /** + * Archive the given records + * + * @param {Array} recordIDs local ids of the records to (un)archive + * @param {string} parentID id of the parent resource to reload + * @returns {Promise} resolves to the parent id + */ + actionArchive: function (recordIDs, parentID) { + var self = this; + var parent = this.localData[parentID]; + var resIDs = _.map(recordIDs, function (recordID) { + return self.localData[recordID].res_id; + }); + return this._rpc({ + model: parent.model, + method: 'action_archive', + args: [resIDs], + }) + .then(function () { + // optionally clear the DataManager's cache + self._invalidateCache(parent); + return self.reload(parentID); + }); + }, + /** + * Unarchive the given records + * + * @param {Array} recordIDs local ids of the records to (un)archive + * @param {string} parentID id of the parent resource to reload + * @returns {Promise} resolves to the parent id + */ + actionUnarchive: function (recordIDs, parentID) { + var self = this; + var parent = this.localData[parentID]; + var resIDs = _.map(recordIDs, function (recordID) { + return self.localData[recordID].res_id; + }); + return this._rpc({ + model: parent.model, + method: 'action_unarchive', + args: [resIDs], }) .then(function () { // optionally clear the DataManager's cache -- cgit v1.2.3 From 71d4116ea379f204d5773d829dce624fbcf67ec5 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Thu, 11 Jul 2019 16:02:05 +0200 Subject: [IMP] web: Make archive:unarchive buttons manage returned actions Purpose ======= When calling toggle_active, you may sometimes retrieve an action to execute. For example, when archiving an employee, it opens a wizard to provide information about the departure, and choose an offboarding plan. This commit modifies the way toggleActive, actionArchive and actionUnarchive works to manage this behavior. --- .../web/static/src/js/views/basic/basic_model.js | 36 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') 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 311b0ee6947..ca0c7829a2c 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1187,10 +1187,18 @@ var BasicModel = AbstractModel.extend({ method: 'toggle_active', args: [resIDs], }) - .then(function () { + .then(function (action) { // optionally clear the DataManager's cache self._invalidateCache(parent); - return self.reload(parentID); + if (!_.isEmpty(action)) { + return self.do_action(action, { + on_close: function () { + return self.reload(parentID); + } + }); + } else { + return self.reload(parentID); + } }); }, /** @@ -1211,10 +1219,18 @@ var BasicModel = AbstractModel.extend({ method: 'action_archive', args: [resIDs], }) - .then(function () { + .then(function (action) { // optionally clear the DataManager's cache self._invalidateCache(parent); - return self.reload(parentID); + if (!_.isEmpty(action)) { + return self.do_action(action, { + on_close: function () { + return self.reload(parentID); + } + }); + } else { + return self.reload(parentID); + } }); }, /** @@ -1235,10 +1251,18 @@ var BasicModel = AbstractModel.extend({ method: 'action_unarchive', args: [resIDs], }) - .then(function () { + .then(function (action) { // optionally clear the DataManager's cache self._invalidateCache(parent); - return self.reload(parentID); + if (!_.isEmpty(action)) { + return self.do_action(action, { + on_close: function () { + return self.reload(parentID); + } + }); + } else { + return self.reload(parentID); + } }); }, /** -- cgit v1.2.3