From a0c7284b6667e2a9f57eed2b19c19fc07174b39d Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 29 Apr 2020 07:21:46 +0000 Subject: [PATCH] [IMP] web: add 'label' attribute on AbstractField If set, this value will be displayed as column name in list views. This attribute could be used in the future in form view for the same purpose. Part of task 2195254 --- .../static/src/js/fields/abstract_field.js | 5 +++ .../src/js/fields/abstract_field_owl.js | 5 +++ .../static/src/js/views/list/list_renderer.js | 5 ++- addons/web/static/tests/views/list_tests.js | 32 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js index 4767f54d998..ab6f226a66e 100644 --- a/addons/web/static/src/js/fields/abstract_field.js +++ b/addons/web/static/src/js/fields/abstract_field.js @@ -81,6 +81,11 @@ var AbstractField = Widget.extend({ * If this flag is set to true, the list column name will be empty. */ noLabel: false, + /** + * Currently only used in list view. + * If set, this value will be displayed as column name. + */ + label: '', /** * Abstract field class * diff --git a/addons/web/static/src/js/fields/abstract_field_owl.js b/addons/web/static/src/js/fields/abstract_field_owl.js index fe908e6ce72..f97faae35ed 100644 --- a/addons/web/static/src/js/fields/abstract_field_owl.js +++ b/addons/web/static/src/js/fields/abstract_field_owl.js @@ -627,6 +627,11 @@ odoo.define('web.AbstractFieldOwl', function (require) { * If this flag is set to true, the list column name will be empty. */ AbstractField.noLabel = false; + /** + * Currently only used in list view. + * If set, this value will be displayed as column name. + */ + AbstractField.label = ""; return AbstractField; }); diff --git a/addons/web/static/src/js/views/list/list_renderer.js b/addons/web/static/src/js/views/list/list_renderer.js index 93576be9348..98febd8efa8 100644 --- a/addons/web/static/src/js/views/list/list_renderer.js +++ b/addons/web/static/src/js/views/list/list_renderer.js @@ -812,8 +812,11 @@ var ListRenderer = BasicRenderer.extend({ var description = string || field.string; if (node.attrs.widget) { $th.addClass(' o_' + node.attrs.widget + '_cell'); - if (this.state.fieldsInfo.list[name].Widget.prototype.noLabel) { + const FieldWidget = this.state.fieldsInfo.list[name].Widget; + if (FieldWidget.prototype.noLabel) { description = ''; + } else if (FieldWidget.prototype.label) { + description = FieldWidget.prototype.label; } } $th.text(description) diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 03e62488ba4..2ad91dcae40 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -304,6 +304,38 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('column names (noLabel, label, string and default)', async function (assert) { + assert.expect(4); + + const FieldChar = fieldRegistry.get('char'); + fieldRegistry.add('nolabel_char', FieldChar.extend({ + noLabel: true, + })); + fieldRegistry.add('label_char', FieldChar.extend({ + label: "Some static label", + })); + + const list = await createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: ` + + + + + + `, + }); + + assert.strictEqual(list.$('thead th[data-name=display_name]').text(), ''); + assert.strictEqual(list.$('thead th[data-name=foo]').text(), 'Some static label'); + assert.strictEqual(list.$('thead th[data-name=int_field]').text(), 'My custom label'); + assert.strictEqual(list.$('thead th[data-name=text]').text(), 'text field'); + + list.destroy(); + }); + QUnit.test('simple editable rendering', async function (assert) { assert.expect(15);