From 0b335ad5107ebdfd74c5ca1c824186f7451bbd5b Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Thu, 19 Jan 2023 17:11:24 +0000 Subject: [PATCH] [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) Signed-off-by: Aaron Bohy (aab) --- .../settings_form_view/settings_form_view.js | 16 ++---- .../settings_form_view_tests.js | 51 ++++++++++++++++++- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/addons/web/static/src/webclient/settings_form_view/settings_form_view.js b/addons/web/static/src/webclient/settings_form_view/settings_form_view.js index 6264075cad3..41924b4c206 100644 --- a/addons/web/static/src/webclient/settings_form_view/settings_form_view.js +++ b/addons/web/static/src/webclient/settings_form_view/settings_form_view.js @@ -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); }, }); diff --git a/addons/web/static/tests/webclient/settings_form_view/settings_form_view_tests.js b/addons/web/static/tests/webclient/settings_form_view/settings_form_view_tests.js index 1550ea97d19..cc792a01468 100644 --- a/addons/web/static/tests/webclient/settings_form_view/settings_form_view_tests.js +++ b/addons/web/static/tests/webclient/settings_form_view/settings_form_view_tests.js @@ -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": ` +
+ +