From cae4e1b1cf984746f7321c18b9f4b746c6743dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Tue, 17 Oct 2023 16:39:18 +0200 Subject: [PATCH] [FIX] web: add fallback of display_name in `formatMany2one`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since https://github.com/odoo/odoo/pull/137098, we add a fallback for false display_name in the form view, but we didn't add it for the list view which doesn't instantiate the Many2one component. It uses `formatMany2one` instead. Fix it to be consistent with the Many2one closes odoo/odoo#139215 Signed-off-by: Aaron Bohy (aab) Signed-off-by: Rémy Voet (ryv) --- .../web/static/src/views/fields/formatters.js | 4 +++- .../tests/views/fields/formatters_tests.js | 1 + .../web/static/tests/views/list_view_tests.js | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/views/fields/formatters.js b/addons/web/static/src/views/fields/formatters.js index 943d40b5751..a796993a086 100644 --- a/addons/web/static/src/views/fields/formatters.js +++ b/addons/web/static/src/views/fields/formatters.js @@ -211,8 +211,10 @@ export function formatInteger(value, options = {}) { export function formatMany2one(value, options) { if (!value) { value = ""; + } else if (value[1]) { + value = value[1]; } else { - value = value[1] || ""; + value = _t("Unnamed"); } if (options && options.escape) { value = encodeURIComponent(value); diff --git a/addons/web/static/tests/views/fields/formatters_tests.js b/addons/web/static/tests/views/fields/formatters_tests.js index b71ad4b71ca..e8587841b72 100644 --- a/addons/web/static/tests/views/fields/formatters_tests.js +++ b/addons/web/static/tests/views/fields/formatters_tests.js @@ -107,6 +107,7 @@ QUnit.module("Fields", (hooks) => { QUnit.test("formatMany2one", function (assert) { assert.strictEqual(formatMany2one(false), ""); assert.strictEqual(formatMany2one([false, "M2O value"]), "M2O value"); + assert.strictEqual(formatMany2one([1, false]), "Unnamed"); assert.strictEqual(formatMany2one([1, "M2O value"]), "M2O value"); assert.strictEqual(formatMany2one([1, "M2O value"], { escape: true }), "M2O%20value"); }); diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js index 8cbd793b090..ce9ad27dd85 100644 --- a/addons/web/static/tests/views/list_view_tests.js +++ b/addons/web/static/tests/views/list_view_tests.js @@ -2560,6 +2560,28 @@ QUnit.module("Views", (hooks) => { ); }); + QUnit.test("many2one field rendering when display_name is falsy", async function (assert) { + serverData.models.bar.records[0].display_name = false + await makeView({ + type: "list", + resModel: "foo", + serverData, + arch: '', + mockRPC(route) { + assert.step(route); + }, + }); + + assert.ok( + $(target).find("td:contains(Unnamed)").length, + "should have a Unnamed as fallback of many2one display_name" + ); + assert.verifySteps([ + "/web/dataset/call_kw/foo/get_views", + "/web/dataset/call_kw/foo/web_search_read", + ]); + }); + QUnit.test("grouped list view, with 1 open group", async function (assert) { await makeView({ type: "list",