From d5986fb9d9796adfb67cfed584ae52cb1d13734b Mon Sep 17 00:00:00 2001 From: "Bastien Fafchamps (bafa)" Date: Tue, 6 Jun 2023 09:41:42 +0000 Subject: [PATCH] [FIX] web: Fix readonly modifier not working with clickable option on statusbar field Before this commit: The readonly readonly modifier of the statusbar field was not taken into account when the "clickable" option was set. After this commit: Even if the "clickable" option is set to true, if a readonly modifier is set, it will prevent (or not) changing the stage of a status bar. closes odoo/odoo#145766 Opw: 3222998 X-original-commit: 9e1d01bc44e5e90ed2b809cfadbd05a5793b3c07 Signed-off-by: Aaron Bohy (aab) Signed-off-by: Bastien Fafchamps (bafa) --- .../views/fields/statusbar/statusbar_field.js | 8 +-- .../views/fields/statusbar_field_tests.js | 61 +++++++++++++++++++ 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/addons/web/static/src/views/fields/statusbar/statusbar_field.js b/addons/web/static/src/views/fields/statusbar/statusbar_field.js index a1eb553eb27..8b106eb17a3 100644 --- a/addons/web/static/src/views/fields/statusbar/statusbar_field.js +++ b/addons/web/static/src/views/fields/statusbar/statusbar_field.js @@ -131,7 +131,7 @@ export class StatusBarField extends Component { { category: "smart_action", hotkey: "alt+shift+x", - isAvailable: () => !this.props.readonly && !this.props.isDisabled, + isAvailable: () => !this.props.isDisabled, } ); useCommand( @@ -145,9 +145,7 @@ export class StatusBarField extends Component { category: "smart_action", hotkey: "alt+x", isAvailable: () => - !this.props.readonly && - !this.props.isDisabled && - !this.getAllItems().at(-1).isSelected, + !this.props.isDisabled && !this.getAllItems().at(-1).isSelected, } ); } @@ -346,7 +344,7 @@ export const statusBarField = { supportedTypes: ["many2one", "selection"], isEmpty: (record, fieldName) => !record.data[fieldName], extractProps: ({ attrs, options, viewType }, dynamicInfo) => ({ - isDisabled: !options.clickable, + isDisabled: !options.clickable || dynamicInfo.readonly, visibleSelection: attrs.statusbar_visible?.trim().split(/\s*,\s*/g), withCommand: viewType === "form", foldField: options.fold_field, diff --git a/addons/web/static/tests/views/fields/statusbar_field_tests.js b/addons/web/static/tests/views/fields/statusbar_field_tests.js index 494ddfd8837..75db7e6acb5 100644 --- a/addons/web/static/tests/views/fields/statusbar_field_tests.js +++ b/addons/web/static/tests/views/fields/statusbar_field_tests.js @@ -707,4 +707,65 @@ QUnit.module("Fields", (hooks) => { assert.verifySteps(["search_read"]); } ); + + QUnit.test( + "clickable statusbar with readonly modifier set to false is editable", + async function (assert) { + await makeView({ + type: "form", + resModel: "partner", + resId: 2, + serverData, + arch: ` +
+
+ +
+
`, + }); + assert.containsN(target, ".o_statusbar_status button:visible", 2); + assert.containsNone( + target, + ".o_statusbar_status button[disabled][aria-checked='false']:visible" + ); + } + ); + + QUnit.test( + "clickable statusbar with readonly modifier set to true is not editable", + async function (assert) { + await makeView({ + type: "form", + resModel: "partner", + resId: 2, + serverData, + arch: ` +
+
+ +
+
`, + }); + assert.containsN(target, ".o_statusbar_status button[disabled]:visible", 2); + } + ); + + QUnit.test( + "non-clickable statusbar with readonly modifier set to false is not editable", + async function (assert) { + await makeView({ + type: "form", + resModel: "partner", + resId: 2, + serverData, + arch: ` +
+
+ +
+
`, + }); + assert.containsN(target, ".o_statusbar_status button[disabled]:visible", 2); + } + ); });