[FIX] web: add fallback of display_name in formatMany2one.

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) <aab@odoo.com>
Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
This commit is contained in:
Rémy Voet (ryv)
2023-10-20 09:35:23 +00:00
parent c3bbba7cdd
commit cae4e1b1cf
3 changed files with 26 additions and 1 deletions
@@ -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);
@@ -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");
});
@@ -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: '<tree><field name="m2o"/></tree>',
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",