[FIX] web: list: correctly evaluate dynamic expand attribute
The `expand` attribute in list views can be dynamic (e.g.
`context.get("some_val_from_ctx", False)`). Before this commit, it
wasn't evaluated, so a dynamic value would always result as true,
as it isn't "O", "false" or "False". To instance, go to Invoices
and add a group by. This commit fixes that issue.
Task 3130159
closes odoo/odoo#110235
X-original-commit: 1072c4880fdd2835b0711869da06681dab20d33c
Signed-off-by: Michaël Mattiello <mcm@odoo.com>
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -203,7 +203,7 @@ export class ListArchParser extends XMLParser {
|
||||
treeAttr.groupsLimit = groupsLimitAttr && parseInt(groupsLimitAttr, 10);
|
||||
|
||||
treeAttr.noOpen = archParseBoolean(node.getAttribute("no_open") || "");
|
||||
treeAttr.expand = archParseBoolean(xmlDoc.getAttribute("expand") || "");
|
||||
treeAttr.rawExpand = xmlDoc.getAttribute("expand");
|
||||
treeAttr.decorations = getDecoration(xmlDoc);
|
||||
|
||||
treeAttr.defaultGroupBy = xmlDoc.getAttribute("default_group_by");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
|
||||
import { download } from "@web/core/network/download";
|
||||
import { evaluateExpr } from "@web/core/py_js/py";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { omit } from "@web/core/utils/objects";
|
||||
import { sprintf } from "@web/core/utils/strings";
|
||||
@@ -37,6 +38,7 @@ export class ListController extends Component {
|
||||
this.activeActions = this.archInfo.activeActions;
|
||||
const fields = this.props.fields;
|
||||
const { rootState } = this.props.state || {};
|
||||
const { defaultGroupBy, rawExpand } = this.archInfo;
|
||||
this.model = useModel(this.props.Model, {
|
||||
resModel: this.props.resModel,
|
||||
fields,
|
||||
@@ -47,8 +49,8 @@ export class ListController extends Component {
|
||||
groupByInfo: this.archInfo.groupBy.fields,
|
||||
limit: this.archInfo.limit || this.props.limit,
|
||||
defaultOrder: this.archInfo.defaultOrder,
|
||||
defaultGroupBy: this.props.searchMenuTypes.includes("groupBy") && this.props.archInfo.defaultGroupBy,
|
||||
expand: this.archInfo.expand,
|
||||
defaultGroupBy: this.props.searchMenuTypes.includes("groupBy") ? defaultGroupBy : false,
|
||||
expand: rawExpand ? evaluateExpr(rawExpand, this.props.context) : false,
|
||||
groupsLimit: this.archInfo.groupsLimit,
|
||||
multiEdit: this.multiEdit,
|
||||
rootState,
|
||||
|
||||
@@ -12347,6 +12347,38 @@ QUnit.module("Views", (hooks) => {
|
||||
]);
|
||||
});
|
||||
|
||||
QUnit.test("grouped list with dynamic expand attribute (eval true)", async function (assert) {
|
||||
await makeView({
|
||||
type: "list",
|
||||
resModel: "foo",
|
||||
serverData,
|
||||
arch: `<tree expand="context.get('expand', False)"><field name="foo"/></tree>`,
|
||||
context: {
|
||||
expand: true,
|
||||
},
|
||||
groupBy: ["bar"],
|
||||
});
|
||||
|
||||
assert.containsN(target, ".o_group_header", 2);
|
||||
assert.containsN(target, ".o_data_row", 4);
|
||||
});
|
||||
|
||||
QUnit.test("grouped list with dynamic expand attribute (eval false)", async function (assert) {
|
||||
await makeView({
|
||||
type: "list",
|
||||
resModel: "foo",
|
||||
serverData,
|
||||
arch: `<tree expand="context.get('expand', False)"><field name="foo"/></tree>`,
|
||||
context: {
|
||||
expand: false,
|
||||
},
|
||||
groupBy: ["bar"],
|
||||
});
|
||||
|
||||
assert.containsN(target, ".o_group_header", 2);
|
||||
assert.containsNone(target, ".o_data_row");
|
||||
});
|
||||
|
||||
QUnit.test("grouped list (two levels) with expand attribute", async function (assert) {
|
||||
// the expand attribute only opens the first level groups
|
||||
await makeView({
|
||||
|
||||
Reference in New Issue
Block a user