From 147d7e8910a7745fce738825a1deda54972f792b Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 3 Apr 2020 09:37:39 +0000 Subject: [PATCH] [FIX] web: form: hide labels of oe_(read|edit)_only fields In a form view, nodes with classname "oe_read_only" (resp. "oe_edit_only") are only visible in readonly (resp. edit) mode. Moreover, fields inside a group automatically have an associated label. Before this commit, when one of these classnames was set on a field node inside a group, the effect wasn't applied on its label, so the label was always visible, even if the field was hidden. Bug reported in PR odoo/odoo#48699 closes odoo/odoo#48968 X-original-commit: 705f434f0f18a0e4d2fdb0f86d3e350d190b2a30 Signed-off-by: Julien Mougenot (jum) Signed-off-by: Aaron Bohy (aab) --- .../static/src/js/views/form/form_renderer.js | 8 +++++ addons/web/static/tests/views/form_tests.js | 35 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/addons/web/static/src/js/views/form/form_renderer.js b/addons/web/static/src/js/views/form/form_renderer.js index a258d16a917..18a5695005f 100644 --- a/addons/web/static/src/js/views/form/form_renderer.js +++ b/addons/web/static/src/js/views/form/form_renderer.js @@ -608,6 +608,14 @@ var FormRenderer = BasicRenderer.extend({ if (node.attrs.nolabel !== '1') { var $labelTd = this._renderInnerGroupLabel(node); $tds = $labelTd.add($tds); + + // apply the oe_(edit|read)_only className on the label as well + if (/\boe_edit_only\b/.test(node.attrs.class)) { + $tds.addClass('oe_edit_only'); + } + if (/\boe_read_only\b/.test(node.attrs.class)) { + $tds.addClass('oe_read_only'); + } } return $tds; diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index ee3c68534e3..e9d1903c14d 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -4717,6 +4717,41 @@ QUnit.module('Views', { form.destroy(); }); + QUnit.test('oe_read_only and oe_edit_only classNames on fields inside groups', async function (assert) { + assert.expect(10); + + const form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: ` +
+ + + + +
`, + res_id: 1, + }); + + assert.hasClass(form.$('.o_form_view'), 'o_form_readonly', + 'form should be in readonly mode'); + assert.isVisible(form.$('.o_field_widget[name=foo]')); + assert.isVisible(form.$('label:contains(Foo)')); + assert.isNotVisible(form.$('.o_field_widget[name=bar]')); + assert.isNotVisible(form.$('label:contains(Bar)')); + + await testUtils.form.clickEdit(form); + assert.hasClass(form.$('.o_form_view'), 'o_form_editable', + 'form should be in readonly mode'); + assert.isNotVisible(form.$('.o_field_widget[name=foo]')); + assert.isNotVisible(form.$('label:contains(Foo)')); + assert.isVisible(form.$('.o_field_widget[name=bar]')); + assert.isVisible(form.$('label:contains(Bar)')); + + form.destroy(); + }); + QUnit.test('oe_read_only className is handled in list views', async function (assert) { assert.expect(7);