From fd381e99af6801b5724fbf791bb4de753030e00a Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Tue, 23 Nov 2021 13:12:42 +0000 Subject: [PATCH] [FIX] web: quickedit on readonly one2many list Steps to follow - Go to the purchase app - Create a RFQ, add a line, confirm it, lock it and save it - Click on the one2many line -> An editable popup is opened and the main form is also switched in edit mode Solution - Check if the one2many list has a readonly modifier before switching the main form to edit mode - When opening the one2many preview popup, pass along an editable param opw-2689420 closes odoo/odoo#80338 X-original-commit: d1c9265659572c738596889f7a5ad53f673e9db4 Signed-off-by: Hubert Van De Walle --- .../src/legacy/js/fields/abstract_field.js | 2 +- .../src/legacy/js/fields/relational_fields.js | 1 + .../static/src/legacy/js/views/abstract_view.js | 3 ++- .../src/legacy/js/views/form/form_controller.js | 2 ++ .../static/src/legacy/js/views/view_dialogs.js | 4 ++++ .../web/static/tests/legacy/views/form_tests.js | 17 ++++++----------- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/addons/web/static/src/legacy/js/fields/abstract_field.js b/addons/web/static/src/legacy/js/fields/abstract_field.js index cbb9267f933..c79c6b8eec1 100644 --- a/addons/web/static/src/legacy/js/fields/abstract_field.js +++ b/addons/web/static/src/legacy/js/fields/abstract_field.js @@ -602,7 +602,7 @@ var AbstractField = Widget.extend({ * @param {MouseEvent} ev */ _onClick: function (ev) { - if (this._canQuickEdit && this.mode === 'readonly' && + if (!this.hasReadonlyModifier && this._canQuickEdit && this.mode === 'readonly' && !this.quickEditExclusion.some(x => ev.target.closest(x)) ) { this.trigger_up('quick_edit', { diff --git a/addons/web/static/src/legacy/js/fields/relational_fields.js b/addons/web/static/src/legacy/js/fields/relational_fields.js index 0b4c11ee302..9c69f088615 100644 --- a/addons/web/static/src/legacy/js/fields/relational_fields.js +++ b/addons/web/static/src/legacy/js/fields/relational_fields.js @@ -2123,6 +2123,7 @@ var FieldOne2Many = FieldX2Many.extend({ parentID: this.value.id, viewInfo: this.view, deletable: this.activeActions.delete && params.deletable && this.canDelete, + editable: !this.hasReadonlyModifier, disable_multiple_selection: params.disable_multiple_selection, })); }, diff --git a/addons/web/static/src/legacy/js/views/abstract_view.js b/addons/web/static/src/legacy/js/views/abstract_view.js index 27d696cce1d..959b68ce5df 100644 --- a/addons/web/static/src/legacy/js/views/abstract_view.js +++ b/addons/web/static/src/legacy/js/views/abstract_view.js @@ -87,6 +87,7 @@ var AbstractView = Factory.extend({ * @param {Array[]} [params.domain=[]] * @param {Object[]} [params.dynamicFilters] transmitted to the * ControlPanel + * @param {boolean} [params.editable] * @param {number[]} [params.ids] * @param {boolean} [params.isEmbedded=false] * @param {Object} [params.searchQuery={}] @@ -139,7 +140,7 @@ var AbstractView = Factory.extend({ this.controllerParams = { actionViews: params.actionViews, activeActions: { - edit: this.arch.attrs.edit ? !!JSON.parse(this.arch.attrs.edit) : true, + edit: typeof params.editable === 'boolean' ? params.editable : this.arch.attrs.edit ? !!JSON.parse(this.arch.attrs.edit) : true, create: this.arch.attrs.create ? !!JSON.parse(this.arch.attrs.create) : true, delete: this.arch.attrs.delete ? !!JSON.parse(this.arch.attrs.delete) : true, duplicate: this.arch.attrs.duplicate ? !!JSON.parse(this.arch.attrs.duplicate) : true, diff --git a/addons/web/static/src/legacy/js/views/form/form_controller.js b/addons/web/static/src/legacy/js/views/form/form_controller.js index af7cf034cef..4cb479fa2a4 100644 --- a/addons/web/static/src/legacy/js/views/form/form_controller.js +++ b/addons/web/static/src/legacy/js/views/form/form_controller.js @@ -664,6 +664,7 @@ var FormController = BasicController.extend({ on_remove: data.on_remove, parentID: data.parentID, readonly: data.readonly, + editable: data.editable, deletable: record ? data.deletable : false, disable_multiple_selection: data.disable_multiple_selection, recordID: record && record.id, @@ -690,6 +691,7 @@ var FormController = BasicController.extend({ on_remove: ev.data.on_remove, readonly: ev.data.readonly, deletable: ev.data.deletable, + editable: ev.data.editable, res_id: record.res_id, res_model: record.model, title: _t("Open: ") + ev.data.string, diff --git a/addons/web/static/src/legacy/js/views/view_dialogs.js b/addons/web/static/src/legacy/js/views/view_dialogs.js index bc79f37a154..73fa8bf72f6 100644 --- a/addons/web/static/src/legacy/js/views/view_dialogs.js +++ b/addons/web/static/src/legacy/js/views/view_dialogs.js @@ -73,6 +73,8 @@ var FormViewDialog = ViewDialog.extend({ * creation mode * @param {boolean} [options.deletable=false] whether or not the record can * be deleted + * @param {boolean} [options.editable=true] whether or not the record can + * be edited * @param {boolean} [options.disable_multiple_selection=false] set to true * to remove the possibility to create several records in a row * @param {function} [options.on_saved] callback executed after saving a @@ -105,6 +107,7 @@ var FormViewDialog = ViewDialog.extend({ this.shouldSaveLocally = options.shouldSaveLocally; this.readonly = options.readonly; this.deletable = options.deletable; + this.editable = options.editable; this.disable_multiple_selection = options.disable_multiple_selection; var oBtnRemove = 'o_btn_remove'; @@ -209,6 +212,7 @@ var FormViewDialog = ViewDialog.extend({ parentID: self.parentID, recordID: self.recordID, isFromFormViewDialog: true, + editable: self.editable }); return formview.getController(self); }).then(function (formView) { diff --git a/addons/web/static/tests/legacy/views/form_tests.js b/addons/web/static/tests/legacy/views/form_tests.js index dccb474fc9a..39c6ab26a44 100644 --- a/addons/web/static/tests/legacy/views/form_tests.js +++ b/addons/web/static/tests/legacy/views/form_tests.js @@ -10935,7 +10935,7 @@ QUnit.module('Views', { }); QUnit.test('Quick Edition: Readonly one2many list', async function (assert) { - assert.expect(7); + assert.expect(4); this.data.partner.records[0].p.push(2); @@ -10962,13 +10962,8 @@ QUnit.module('Views', { await testUtils.dom.click(form.$('.o_field_cell:first')); - assert.containsOnce(form, '.o_form_view.o_form_editable', - 'should switch into edit mode'); - assert.containsNone(form, '.o_field_x2many_list_row_add', - 'create line should still not be displayed'); - assert.containsNone(form, '.o_list_record_remove', - 'remove buttons should still not be displayed'); - assert.containsNone(form, 'input'); + assert.containsOnce(form, '.o_form_view.o_form_readonly', + 'should not switch into edit mode'); form.destroy(); }); @@ -11326,7 +11321,7 @@ QUnit.module('Views', { await testUtils.dom.click(form.$('.o_field_widget[name="timmy"] label:eq(1)')); - assert.containsOnce(form, '.o_form_view.o_form_editable'); + assert.containsOnce(form, '.o_form_view.o_form_readonly'); assert.containsNone(form, 'input[type="checkbox"]:not(:disabled)'); assert.containsNone(form, 'input[type="checkbox"]:checked'); @@ -11408,9 +11403,9 @@ QUnit.module('Views', { await testUtils.dom.click(form.$('.o_field_widget[name="trululu"] label:eq(1)')); - assert.containsOnce(form, '.o_form_view.o_form_editable'); + assert.containsOnce(form, '.o_form_view.o_form_readonly'); assert.containsOnce(form, 'input[type="radio"]:eq(2):checked'); - assert.containsNone(form, 'input[type="checkbox"]:not(:disabled)'); + assert.containsNone(form, 'input[type="radio"]:not(:disabled)'); form.destroy(); });