[FIX] web: settings view: call server actions with the resId
Steps to reproduce ================== - Go to settings - Search for IAP - Click on View My Services Cause of the issue ================== In the settings view, there is a specific hack which removes the resId from the record https://github.com/odoo/odoo/blob/e4fe05ac07dbafb993922ff28dc3f7705c639dff/addons/web/static/src/webclient/settings_form_view/settings_form_view.js#L35-L39 This means that the records is not defined in the server action and so nothing is done https://github.com/odoo/odoo/blob/cd356f29abcaa1029e8a79ae76c2561f4833232a/addons/iap/views/res_config_settings.xml#L9 Solution ======== Instead of removing the res_id to mark the record as new, override BasicModel.isNew opw-3120995 closes odoo/odoo#110679 X-original-commit: ffb09c4ba5a4fb521a242adb0541595bd3ec1524 Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com> Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -9,18 +9,10 @@ import { SettingsFormCompiler } from "./settings_form_compiler";
|
||||
import BasicModel from "web.BasicModel";
|
||||
|
||||
const BaseSettingsModel = BasicModel.extend({
|
||||
save(recordID, options) {
|
||||
const savePoint = options && options.savePoint;
|
||||
return this._super.apply(this, arguments).then((result) => {
|
||||
if (!savePoint && this.localData[recordID].model === "res.config.settings") {
|
||||
// we remove here the res_id, because the record should still be
|
||||
// considered new. We want the web client to always perform a
|
||||
// onchange to fetch the settings data.
|
||||
this.localData[recordID].res_ids = [this.localData[recordID].res_id];
|
||||
delete this.localData[recordID].res_id;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
isNew(id) {
|
||||
return this.localData[id].model === "res.config.settings"
|
||||
? true
|
||||
: this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import { SettingsFormCompiler } from "@web/webclient/settings_form_view/settings
|
||||
import { registerCleanup } from "../../helpers/cleanup";
|
||||
import { makeFakeLocalizationService } from "@web/../tests/helpers/mock_services";
|
||||
import { session } from "@web/session";
|
||||
import { pick } from "@web/core/utils/objects";
|
||||
|
||||
let target;
|
||||
let serverData;
|
||||
@@ -1004,7 +1005,7 @@ QUnit.module("SettingsFormView", (hooks) => {
|
||||
assert.verifySteps([
|
||||
"create",
|
||||
"read",
|
||||
'action executed {"name":"execute","type":"object","resModel":"res.config.settings","resIds":[1],"context":{"lang":"en","uid":7,"tz":"taht"},"buttonContext":{}}',
|
||||
'action executed {"name":"execute","type":"object","resModel":"res.config.settings","resId":1,"resIds":[1],"context":{"lang":"en","uid":7,"tz":"taht"},"buttonContext":{}}',
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1045,7 +1046,7 @@ QUnit.module("SettingsFormView", (hooks) => {
|
||||
assert.verifySteps([
|
||||
"create",
|
||||
"read",
|
||||
'action executed {"context":{"lang":"en","uid":7,"tz":"taht"},"type":"object","name":"mymethod","resModel":"res.config.settings","resIds":[1],"buttonContext":{}}',
|
||||
'action executed {"context":{"lang":"en","uid":7,"tz":"taht"},"type":"object","name":"mymethod","resModel":"res.config.settings","resId":1,"resIds":[1],"buttonContext":{}}',
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1683,4 +1684,50 @@ QUnit.module("SettingsFormView", (hooks) => {
|
||||
await click(target.querySelector(".settings_tab [data-key='otherapp']"));
|
||||
assert.strictEqual(scrollingEl.scrollTop, scrollTop);
|
||||
});
|
||||
|
||||
QUnit.test("server actions are called with the correct context", async (assert) => {
|
||||
serverData.actions = {
|
||||
1: {
|
||||
id: 1,
|
||||
name: "Settings view",
|
||||
res_model: "res.config.settings",
|
||||
type: "ir.actions.act_window",
|
||||
views: [[1, "form"]],
|
||||
},
|
||||
2: {
|
||||
model_name: "partner",
|
||||
name: "Action partner",
|
||||
type: "ir.actions.server",
|
||||
usage: "ir_actions_server",
|
||||
},
|
||||
};
|
||||
|
||||
serverData.views = {
|
||||
"res.config.settings,1,form": `
|
||||
<form string="Settings" class="oe_form_configuration o_base_settings" js_class="base_settings">
|
||||
<app string="CRM" name="crm">
|
||||
<button name="2" type="action"/>
|
||||
</app>
|
||||
</form>
|
||||
`,
|
||||
"res.config.settings,false,search": "<search></search>",
|
||||
};
|
||||
|
||||
const mockRPC = (route, args) => {
|
||||
if (route === "/web/action/run") {
|
||||
assert.step(route);
|
||||
assert.deepEqual(pick(args.context, "active_id", "active_ids", "active_model"), {
|
||||
active_id: 1,
|
||||
active_ids: [1],
|
||||
active_model: "res.config.settings",
|
||||
});
|
||||
return new Promise(() => {});
|
||||
}
|
||||
};
|
||||
|
||||
const webClient = await createWebClient({ serverData, mockRPC });
|
||||
await doAction(webClient, 1);
|
||||
await click(target.querySelector("button[name='2']"));
|
||||
assert.verifySteps(["/web/action/run"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user