From 8d17a2ae557aeddd68dd2fe78b6c052bbcc183c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Tue, 24 Apr 2018 12:33:50 +0200 Subject: [PATCH] [FIX] base: do not read settings record again The settings view is supposed to open a new record on the model res.config.settings, perform the default_get and onchange calls, then display the result. However, once this is done, if the user then clicked on some links (which do save the current record and navigate to another action), then click on the breadcrumbs to come back to the settings view, then the settings view will reload the current record, which has an id, and this also will update the url. This could be a problem. For example, in a multicompany settings, reloading a settings view from an id will reload the settings for a given company, even if the user changed its current company. To fix this issue, we make sure the basic model for the settings view 'forgets' the res_id key, so it will be compelled to actually reread a new settings form record. --- .../base/static/src/js/res_config_settings.js | 19 ++++++ .../static/src/tests/base_setting_test.js | 58 ++++++++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/static/src/js/res_config_settings.js b/odoo/addons/base/static/src/js/res_config_settings.js index 8285133c64c..041e6494f64 100644 --- a/odoo/addons/base/static/src/js/res_config_settings.js +++ b/odoo/addons/base/static/src/js/res_config_settings.js @@ -1,6 +1,7 @@ odoo.define('base.settings', function (require) { "use strict"; +var BasicModel = require('web.BasicModel'); var core = require('web.core'); var config = require('web.config'); var FormView = require('web.FormView'); @@ -329,8 +330,25 @@ var BaseSettingController = FormController.extend({ }, }); +var BaseSettingsModel = BasicModel.extend({ + /** + * @override + */ + save: function (recordID) { + var self = this; + return this._super.apply(this, arguments).then(function (result) { + // we remove here the res_id, because the record should still be + // considered new. We want the web client to always perform a + // default_get to fetch the settings anew. + delete self.localData[recordID].res_id; + return result; + }); + }, +}); + var BaseSettingView = FormView.extend({ config: _.extend({}, FormView.prototype.config, { + Model: BaseSettingsModel, Renderer: BaseSettingRenderer, Controller: BaseSettingController, }), @@ -343,6 +361,7 @@ var BaseSettingView = FormView.extend({ view_registry.add('base_settings', BaseSettingView); return { + Model: BaseSettingsModel, Renderer: BaseSettingRenderer, Controller: BaseSettingController, }; diff --git a/odoo/addons/base/static/src/tests/base_setting_test.js b/odoo/addons/base/static/src/tests/base_setting_test.js index 10a00e2713c..3964751a538 100644 --- a/odoo/addons/base/static/src/tests/base_setting_test.js +++ b/odoo/addons/base/static/src/tests/base_setting_test.js @@ -8,6 +8,8 @@ var view_registry = require('web.view_registry'); var createView = testUtils.createView; var BaseSettingsView = view_registry.get('base_settings'); +var createActionManager = testUtils.createActionManager; + BaseSetting.Renderer.include({ _getAppIconUrl: function() { @@ -91,5 +93,59 @@ QUnit.module('base_settings_tests', { assert.strictEqual(form.$('.notFound').hasClass('o_hidden'),false,"record not found message shown"); form.destroy(); }); + + QUnit.test('settings views does not read existing id when coming back in breadcrumbs', function (assert) { + assert.expect(7); + + var actions = [{ + id: 1, + name: 'Settings view', + res_model: 'project', + type: 'ir.actions.act_window', + views: [[1, 'form']], + }, { + id: 4, + name: 'Other action', + res_model: 'project', + type: 'ir.actions.act_window', + views: [[2, 'list']], + }]; + var archs = { + 'project,1,form': '
' + + '
' + + '
' + + '
', + 'project,2,list': '', + 'project,false,search': '', + }; + + var actionManager = createActionManager({ + actions: actions, + archs: archs, + data: this.data, + mockRPC: function (route, args) { + if (args.method) { + assert.step(args.method); + } + return this._super.apply(this, arguments); + }, + }); + + actionManager.doAction(1); + actionManager.$('button[name="4"]').click(); + $('.o_control_panel .breadcrumb li a').click(); + assert.verifySteps([ + 'load_views', // initial setting action + 'default_get', // this is a setting view => create new record + 'create', // when we click on action button => save + 'read', // with save, we have a reload... (not necessary actually) + 'load_views', // for other action in breadcrumb, + // with a searchread (not shown here since it is a route) + 'default_get', // when we come back, we want to restart from scratch + ]); + + actionManager.destroy(); + }); +}); }); -}); \ No newline at end of file