From 6ebf19b18924dc79c11019c96bde8bb2fa18a548 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Tue, 19 Jul 2022 13:24:21 +0000 Subject: [PATCH] [FIX] web: fix statusbar field not displaying correct value in mobile Previously, the statusbar field didn't display the currently selected value for selection field in mobile, as the getter to compute the name of the currently selected item only accounted for the many2one case but not for the selection field case. This commit adds handling for the selection field case and a test for it. Part-of: odoo/odoo#78221 --- .../views/fields/statusbar/statusbar_field.js | 13 ++++++-- .../views/fields/statusbar_field_tests.js | 31 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 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 08009f55187..d050d4e908e 100644 --- a/addons/web/static/src/views/fields/statusbar/statusbar_field.js +++ b/addons/web/static/src/views/fields/statusbar/statusbar_field.js @@ -20,8 +20,17 @@ export class StatusBarField extends Component { } get currentName() { - const item = this.options.find((item) => item.isSelected); - return item ? item.name : ""; + switch (this.props.record.fields[this.props.name].type) { + case "many2one": { + const item = this.options.find((item) => item.isSelected); + return item ? item.name : ""; + } + case "selection": { + const item = this.options.find((item) => item[0] === this.props.value); + return item ? item[1] : ""; + } + } + throw new Error("Unsupported field type for StatusBarField"); } get options() { switch (this.props.record.fields[this.props.name].type) { 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 0c267c9127a..fd43f566310 100644 --- a/addons/web/static/tests/views/fields/statusbar_field_tests.js +++ b/addons/web/static/tests/views/fields/statusbar_field_tests.js @@ -166,6 +166,37 @@ QUnit.module("Fields", (hooks) => { ); }); + QUnit.test( + "folded statusbar widget on selection field has selected value in the toggler", + async function (assert) { + registry.category("services").add("ui", { + start(env) { + Object.defineProperty(env, "isSmall", { + value: true, + }); + return { + size: 0, + isSmall: true, + }; + }, + }); + await makeView({ + type: "form", + resModel: "partner", + resId: 1, + serverData, + arch: ` +
+
+ +
+
`, + }); + + assert.containsOnce(target, ".o_statusbar_status button.dropdown-toggle:contains(Red)"); + } + ); + QUnit.test("static statusbar widget on many2one field with domain", async function (assert) { assert.expect(1);