[FIX] web: support oe_read_only and oe_edit_only in x2m list

Back-ported from the master,
commit ca9a733b27

Before this rev., classNames 'oe_read_only' (only display in
readonly mode) and 'oe_edit_only' (only display in edit mode)
didn't work in x2m lists inside form views (only the cells in the
tbody were hidden, but not the header). This rev. makes this work.

Task 1949618

closes odoo/odoo#36117

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>

closes odoo/odoo#36285

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Jinal Patel
2019-08-30 13:55:56 +00:00
committed by svs-odoo
parent 50464f5461
commit 5a1fb85ef6
2 changed files with 85 additions and 0 deletions
@@ -745,6 +745,14 @@ var ListRenderer = BasicRenderer.extend({
var isNodeSorted = order[0] && order[0].name === name;
var field = this.state.fields[name];
var $th = $('<th>');
if (node.attrs.class) {
if (node.attrs.class.indexOf('oe_edit_only') !== -1) {
$th.addClass('oe_edit_only');
}
if (node.attrs.class.indexOf('oe_read_only') !== -1) {
$th.addClass('oe_read_only');
}
}
if (!field) {
return $th;
}
@@ -4627,6 +4627,83 @@ QUnit.module('Views', {
form.destroy();
});
QUnit.test('oe_read_only className is handled in list views', async function (assert) {
assert.expect(5);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="p">' +
'<tree editable="top">' +
'<field name="foo"/>' +
'<field name="display_name" class="oe_read_only"/>' +
'<field name="bar"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
res_id: 1,
});
assert.hasClass(form.$('.o_form_view'), 'o_form_readonly',
'form should be in readonly mode');
assert.isVisible(form.$('.o_field_one2many .o_list_view thead th[data-name="display_name"]'),
'display_name cell should be visible in readonly mode');
await testUtils.form.clickEdit(form);
assert.hasClass(form.$('.o_form_view'), 'o_form_editable',
'form should be in edit mode');
assert.isNotVisible(form.$('.o_field_one2many .o_list_view thead th[data-name="display_name"]'),
'display_name cell should not be visible in edit mode');
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
assert.hasClass(form.$('.o_form_view .o_list_view tbody tr:first input[name="display_name"]'),
'oe_read_only', 'display_name input should have oe_read_only class');
form.destroy();
});
QUnit.test('oe_edit_only className is handled in list views', async function (assert) {
assert.expect(5);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="p">' +
'<tree editable="top">' +
'<field name="foo"/>' +
'<field name="display_name" class="oe_edit_only"/>' +
'<field name="bar"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
res_id: 1,
});
assert.hasClass(form.$('.o_form_view'), 'o_form_readonly',
'form should be in readonly mode');
assert.isNotVisible(form.$('.o_field_one2many .o_list_view thead th[data-name="display_name"]'),
'display_name cell should not be visible in readonly mode');
await testUtils.form.clickEdit(form);
assert.hasClass(form.$('.o_form_view'), 'o_form_editable',
'form should be in edit mode');
assert.isVisible(form.$('.o_field_one2many .o_list_view thead th[data-name="display_name"]'),
'display_name cell should be visible in edit mode');
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
assert.hasClass(form.$('.o_form_view .o_list_view tbody tr:first input[name="display_name"]'),
'oe_edit_only', 'display_name input should have oe_edit_only class');
form.destroy();
});
QUnit.test('*_view_ref in context are passed correctly', async function (assert) {
var done = assert.async();
assert.expect(3);