From 6ae3fc50c505981998e7fbc2a67028bf83de06b9 Mon Sep 17 00:00:00 2001 From: "Audric Onockx (auon)" Date: Tue, 8 Mar 2022 11:44:59 +0000 Subject: [PATCH] [FIX] web : disable archive when active is readonly Steps : Install Sale / E-commerce. Create product P (price = 100). Create price list L aka product_pricelist. Create price rule R (product = P, price = 50) aka product_pricelist_item. Go to product P > Price Rules > archive R. Issue : This should not be possible, as product_pricelist_item.active is a readonly field (related to pricelist_id.active). Fix : Make BasicView.controller.archiveEnabled depend on that. opw-2752184 closes odoo/odoo#86018 Signed-off-by: Aaron Bohy (aab) --- .../src/legacy/js/views/basic/basic_view.js | 4 +++- .../static/tests/legacy/views/list_tests.js | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/legacy/js/views/basic/basic_view.js b/addons/web/static/src/legacy/js/views/basic/basic_view.js index 5f078b1bb14..d9b48473a7e 100644 --- a/addons/web/static/src/legacy/js/views/basic/basic_view.js +++ b/addons/web/static/src/legacy/js/views/basic/basic_view.js @@ -50,7 +50,9 @@ var BasicView = AbstractView.extend({ this.rendererParams.viewType = this.viewType; this.controllerParams.confirmOnDelete = true; - this.controllerParams.archiveEnabled = 'active' in this.fields || 'x_active' in this.fields; + this.controllerParams.archiveEnabled = 'active' in this.fields ? !this.fields.active.readonly + : 'x_active' in this.fields ? !this.fields.x_active.readonly + : false; this.controllerParams.hasButtons = 'action_buttons' in params ? params.action_buttons : true; this.controllerParams.viewId = viewInfo.view_id; diff --git a/addons/web/static/tests/legacy/views/list_tests.js b/addons/web/static/tests/legacy/views/list_tests.js index 5f0d4b93415..91d621bd79e 100644 --- a/addons/web/static/tests/legacy/views/list_tests.js +++ b/addons/web/static/tests/legacy/views/list_tests.js @@ -12736,6 +12736,30 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('archive/unarchive not available on active readonly models', async function (assert) { + assert.expect(2); + + this.data.foo.fields.active = { string: 'Active', type: 'boolean', default: true, readonly: true }; + + const list = await createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: '', + viewOptions: { + hasActionMenus: true, + }, + }); + + await testUtils.dom.click(list.$('tbody .o_data_row:first td.o_list_record_selector:first input')); + assert.containsOnce(list, '.o_cp_action_menus', 'sidebar should be available'); + + await testUtils.dom.click(list.$('.o_cp_action_menus .dropdown-toggle:contains(Action)')); + assert.containsNone(list, 'a:contains(Archive)', 'Archive action should not be available'); + + list.destroy(); + }); + }); });