From 263bef0737a8607e68c4ec874e35248978b8bba5 Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Wed, 20 Jul 2022 12:29:09 +0000 Subject: [PATCH] [FIX] web: ListView use the correct label This commit solves 2 problems in the list view: - incorrect label for a column - the label in the optional column dropdown can be different than the label of the displayed column When converting the list view, we used the displayName of the widget and not its label. In order to improve the consistency between the labels in the optional column dropdown and the associated columns, we decided to use the same label. closes odoo/odoo#96408 Signed-off-by: Aaron Bohy (aab) --- .../static/src/views/list/list_arch_parser.js | 6 ++---- .../static/src/views/list/list_renderer.js | 2 +- .../static/src/views/list/list_renderer.xml | 2 +- .../web/static/tests/views/list_view_tests.js | 21 ++++++++++++++----- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/addons/web/static/src/views/list/list_arch_parser.js b/addons/web/static/src/views/list/list_arch_parser.js index 96ea4d47783..d89c2a9adba 100644 --- a/addons/web/static/src/views/list/list_arch_parser.js +++ b/addons/web/static/src/views/list/list_arch_parser.js @@ -86,7 +86,7 @@ export class ListArchParser extends XMLParser { } addFieldDependencies(activeFields, fieldInfo.FieldComponent.fieldDependencies); if (!invisible || !archParseBoolean(invisible)) { - const displayName = fieldInfo.FieldComponent.displayName; + const label = fieldInfo.FieldComponent.label; columns.push({ ...fieldInfo, id: `column_${nextId++}`, @@ -94,9 +94,7 @@ export class ListArchParser extends XMLParser { optional: node.getAttribute("optional") || false, type: "field", hasLabel: !(fieldInfo.noLabel || fieldInfo.FieldComponent.noLabel), - label: - (fieldInfo.widget && displayName && displayName.toString()) || - fieldInfo.string, + label: (fieldInfo.widget && label && label.toString()) || fieldInfo.string, }); } return false; diff --git a/addons/web/static/src/views/list/list_renderer.js b/addons/web/static/src/views/list/list_renderer.js index b43dd1354dd..d5142d11304 100644 --- a/addons/web/static/src/views/list/list_renderer.js +++ b/addons/web/static/src/views/list/list_renderer.js @@ -435,7 +435,7 @@ export class ListRenderer extends Component { return this.allColumns .filter((col) => col.optional) .map((col) => ({ - string: col.string, + label: col.label, name: col.name, value: this.optionalActiveFields[col.name], })); diff --git a/addons/web/static/src/views/list/list_renderer.xml b/addons/web/static/src/views/list/list_renderer.xml index 6f2e0354ad3..dc1c3883761 100644 --- a/addons/web/static/src/views/list/list_renderer.xml +++ b/addons/web/static/src/views/list/list_renderer.xml @@ -80,7 +80,7 @@ value="field.value" name="field.name" > - + diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js index d2a3ccc5f51..852fc432e61 100644 --- a/addons/web/static/tests/views/list_view_tests.js +++ b/addons/web/static/tests/views/list_view_tests.js @@ -846,7 +846,7 @@ QUnit.module("Views", (hooks) => { fieldRegistry.add("nolabel_char", NoLabelCharField); class LabelCharField extends CharField {} - LabelCharField.displayName = "Some static label"; + LabelCharField.label = "Some static label"; fieldRegistry.add("label_char", LabelCharField); await makeView({ @@ -855,10 +855,10 @@ QUnit.module("Views", (hooks) => { serverData, arch: ` - - - - + + + + `, }); @@ -870,6 +870,17 @@ QUnit.module("Views", (hooks) => { "My custom label", "text field", ]); + + await click(target, "table .o_optional_columns_dropdown .dropdown-toggle"); + const optionalColumnLabels = [ + ...target.querySelectorAll(".o_optional_columns_dropdown .dropdown-item"), + ].map((item) => item.textContent.trim()); + assert.deepEqual(optionalColumnLabels, [ + "Display Name", + "Some static label", + "My custom label", + "text field", + ]); }); QUnit.test("simple editable rendering", async function (assert) {