From 5a1fb85ef681d1197f22b7c1e2ed8a9fc2898cac Mon Sep 17 00:00:00 2001 From: Jinal Patel Date: Tue, 30 Jul 2019 06:19:09 +0000 Subject: [PATCH] [FIX] web: support oe_read_only and oe_edit_only in x2m list Back-ported from the master, commit ca9a733b27a1680403961eaa13cc62e5aa58a8fb 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) closes odoo/odoo#36285 Signed-off-by: Aaron Bohy (aab) --- .../static/src/js/views/list/list_renderer.js | 8 ++ addons/web/static/tests/views/form_tests.js | 77 +++++++++++++++++++ 2 files changed, 85 insertions(+) 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 31300ae53d1..8138b225528 100644 --- a/addons/web/static/src/js/views/list/list_renderer.js +++ b/addons/web/static/src/js/views/list/list_renderer.js @@ -745,6 +745,14 @@ var ListRenderer = BasicRenderer.extend({ var isNodeSorted = order[0] && order[0].name === name; var field = this.state.fields[name]; var $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; } diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 765beb7ed08..1c0c9ae9485 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -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: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
', + 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: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
', + 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);