[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) <jum@odoo.com>
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Aaron Bohy
2020-04-03 11:41:05 +00:00
parent 540df68b32
commit 147d7e8910
2 changed files with 43 additions and 0 deletions
@@ -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;
@@ -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: `
<form>
<group>
<field name="foo" class="oe_read_only"/>
<field name="bar" class="oe_edit_only"/>
</group>
</form>`,
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);