From 66d9fe67a66565a41b2f868e462047cab5ed5aed Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 14 Sep 2022 12:48:12 +0000 Subject: [PATCH] [FIX] web: Many2OneField: do not display a link if unset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, an empty many2one field in readonly rendered an empty `` node. Even though that link was no visible, it had a non null width, and was thus clickable (the cursor changed when hovering it). When clicked, it opened the form view of the comodel, in create mode. This commit fixes the issue by not rendering anything if the value is false. closes odoo/odoo#100158 Signed-off-by: Géry Debongnie --- .../views/fields/many2one/many2one_field.xml | 1 + .../fields/many2one_avatar_field_tests.js | 4 ++-- .../views/fields/many2one_field_tests.js | 21 ++++++++++++------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/addons/web/static/src/views/fields/many2one/many2one_field.xml b/addons/web/static/src/views/fields/many2one/many2one_field.xml index 29f91df2069..1236c181db4 100644 --- a/addons/web/static/src/views/fields/many2one/many2one_field.xml +++ b/addons/web/static/src/views/fields/many2one/many2one_field.xml @@ -26,6 +26,7 @@ { assert.deepEqual( getNodesTextContent(target.querySelectorAll(".o_data_cell .o_form_uri span")), - ["Aline", "Christine", "Aline", ""] + ["Aline", "Christine", "Aline"] ); const imgs = target.querySelectorAll(".o_m2o_avatar > img"); assert.strictEqual(imgs[0].dataset.src, "/web/image/user/17/avatar_128"); @@ -205,7 +205,7 @@ QUnit.module("Fields", (hooks) => { assert.deepEqual( getNodesTextContent(target.querySelectorAll(".o_data_cell .o_form_uri span")), - ["Aline", "Christine", "Aline", ""] + ["Aline", "Christine", "Aline"] ); const imgs = target.querySelectorAll(".o_m2o_avatar > img"); diff --git a/addons/web/static/tests/views/fields/many2one_field_tests.js b/addons/web/static/tests/views/fields/many2one_field_tests.js index 3495b2f432d..c34762204bf 100644 --- a/addons/web/static/tests/views/fields/many2one_field_tests.js +++ b/addons/web/static/tests/views/fields/many2one_field_tests.js @@ -959,6 +959,18 @@ QUnit.module("Fields", (hooks) => { ); }); + QUnit.test("empty readonly many2one field", async function (assert) { + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: `
`, + }); + + assert.containsOnce(target, "div.o_field_widget[name=trululu]"); + assert.strictEqual(target.querySelector(".o_field_widget[name=trululu]").innerHTML, ""); + }); + QUnit.test("empty many2one field with node options", async function (assert) { assert.expect(2); @@ -1207,17 +1219,12 @@ QUnit.module("Fields", (hooks) => { "href should contain id and model" ); - // Remove value from many2one and then save, there should not have href with id and model on m2o anchor + // Remove value from many2one and then save, there should be no link anymore await click(target, ".o_form_button_edit"); await editInput(target, ".o_field_many2one input", ""); await click(target, ".o_form_button_save"); - assert.hasAttrValue( - target.querySelector("a.o_form_uri"), - "href", - "#", - "href should have #" - ); + assert.containsNone(target, "a.o_form_uri"); }); QUnit.test("many2one with co-model whose name field is a many2one", async function (assert) {