[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
This commit is contained in:
Samuel Degueldre
2022-07-22 16:21:43 +02:00
committed by Géry Debongnie
parent 3562946bf3
commit 6ebf19b189
2 changed files with 42 additions and 2 deletions
@@ -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) {
@@ -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: `
<form>
<header>
<field name="color" widget="statusbar" />
</header>
</form>`,
});
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);