From b110bd4cbef272f311680ce8cba39b727b2d6c42 Mon Sep 17 00:00:00 2001 From: "Michael Mattiello (mcm)" Date: Tue, 14 Apr 2020 08:04:09 +0000 Subject: [PATCH] [FIX] web: fix httpRequest GET + add in test_env This commit fixes the method GET in httpRequest and adds it in test_env. Before this commit, the GET method crashed because of the forced body param. closes odoo/odoo#51980 X-original-commit: 7c4fba660a13c38048020faf595bd348d1bca225 Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/js/env.js | 33 +++++++++++---------- addons/web/static/tests/helpers/test_env.js | 3 ++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/addons/web/static/src/js/env.js b/addons/web/static/src/js/env.js index 272a1f77ead..c95cbd3045a 100644 --- a/addons/web/static/src/js/env.js +++ b/addons/web/static/src/js/env.js @@ -22,25 +22,28 @@ odoo.define("web.env", function (require) { } function httpRequest(route, params = {}, readMethod = 'json') { - const formData = new FormData(); - for (const key in params) { - if (key === 'method') { - continue; - } - const value = params[key]; - if (Array.isArray(value) && value.length) { - for (const val of value) { - formData.append(key, val); + const info = { + method: params.method || 'POST', + }; + if (params.method !== 'GET') { + const formData = new FormData(); + for (const key in params) { + if (key === 'method') { + continue; + } + const value = params[key]; + if (Array.isArray(value) && value.length) { + for (const val of value) { + formData.append(key, val); + } + } else { + formData.append(key, value); } - } else { - formData.append(key, value); } + info.body = formData; } - return fetch(route, { - method: params.method || 'POST', - body: formData, - }).then(response => response[readMethod]()); + return fetch(route, info).then(response => response[readMethod]()); } function navigate(url, params) { diff --git a/addons/web/static/tests/helpers/test_env.js b/addons/web/static/tests/helpers/test_env.js index b61024454ed..5b197451517 100644 --- a/addons/web/static/tests/helpers/test_env.js +++ b/addons/web/static/tests/helpers/test_env.js @@ -49,6 +49,9 @@ odoo.define('web.test_env', async function (require) { }, }, getCookie() { }, + httpRequest() { + return Promise.resolve(''); + }, rpc(params, options) { const query = buildQuery(params); return testEnv.session.rpc(query.route, query.params, options);