[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.
This commit is contained in:
Géry Debongnie
2018-04-24 14:42:34 +02:00
parent 7113b70762
commit 8d17a2ae55
2 changed files with 76 additions and 1 deletions
@@ -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,
};
@@ -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': '<form string="Settings" js_class="base_settings">' +
'<div class="app_settings_block" string="CRM" data-key="crm">' +
'<button name="4" string="Execute action" type="action"/>' +
'</div>' +
'</form>',
'project,2,list': '<tree><field name="foo"/></tree>',
'project,false,search': '<search></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();
});
});
});
});