[IMP] web: add default_group_by in list view
Before this commit it is not possible to add default groupBy in list if users want default groupBy a list then they have to pass default groupBy in action and passing default groupBy in action groupBy other views in action, so priorer to this commit users cannot add default groupBy in list view without impacting other view. In, this commit add default_group_by in list view attribute so users can add default groupBy in list view without impacting other views in action. task-3084850 Part-of: odoo/odoo#109281
This commit is contained in:
committed by
Xavier BOL (xbo)
parent
262c0ad84f
commit
3cd30d1531
@@ -68,7 +68,6 @@ export class ListArchParser extends XMLParser {
|
||||
const groupListArchParser = new GroupListArchParser();
|
||||
let buttonGroup;
|
||||
let handleField = null;
|
||||
let defaultOrder = stringToOrderBy(xmlDoc.getAttribute("default_order") || null);
|
||||
const treeAttr = {};
|
||||
let nextId = 0;
|
||||
const activeFields = {};
|
||||
@@ -207,6 +206,9 @@ export class ListArchParser extends XMLParser {
|
||||
treeAttr.expand = archParseBoolean(xmlDoc.getAttribute("expand") || "");
|
||||
treeAttr.decorations = getDecoration(xmlDoc);
|
||||
|
||||
treeAttr.defaultGroupBy = xmlDoc.getAttribute("default_group_by");
|
||||
treeAttr.defaultOrder = stringToOrderBy(xmlDoc.getAttribute("default_order") || null);
|
||||
|
||||
// custom open action when clicking on record row
|
||||
const action = xmlDoc.getAttribute("action");
|
||||
const type = xmlDoc.getAttribute("type");
|
||||
@@ -214,8 +216,8 @@ export class ListArchParser extends XMLParser {
|
||||
}
|
||||
});
|
||||
|
||||
if (!defaultOrder.length && handleField) {
|
||||
defaultOrder = stringToOrderBy(handleField);
|
||||
if (!treeAttr.defaultOrder.length && handleField) {
|
||||
treeAttr.defaultOrder = stringToOrderBy(handleField);
|
||||
}
|
||||
|
||||
for (const [key, field] of Object.entries(fieldNodes)) {
|
||||
@@ -230,7 +232,6 @@ export class ListArchParser extends XMLParser {
|
||||
activeFields,
|
||||
columns,
|
||||
groupBy,
|
||||
defaultOrder,
|
||||
__rawArch: arch,
|
||||
...treeAttr,
|
||||
};
|
||||
|
||||
@@ -70,6 +70,7 @@ 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,
|
||||
groupsLimit: this.archInfo.groupsLimit,
|
||||
multiEdit: this.multiEdit,
|
||||
|
||||
@@ -16634,4 +16634,43 @@ QUnit.module("Views", (hooks) => {
|
||||
await click(target, ".o_field_many2one_selection .o-autocomplete--input");
|
||||
assert.verifySteps(["name_search"]);
|
||||
});
|
||||
|
||||
QUnit.test("list view with default_group_by", async (assert) => {
|
||||
serverData.models.foo.fields.m2m.store = true;
|
||||
|
||||
let readGroupCount = 0;
|
||||
await makeView({
|
||||
type: "list",
|
||||
resModel: "foo",
|
||||
serverData,
|
||||
arch: `
|
||||
<tree default_group_by="bar">
|
||||
<field name="bar"/>
|
||||
</tree>
|
||||
`,
|
||||
async mockRPC(route, { kwargs }) {
|
||||
if (route === "/web/dataset/call_kw/partner/web_read_group") {
|
||||
readGroupCount++;
|
||||
switch (readGroupCount) {
|
||||
case 1:
|
||||
return assert.deepEqual(kwargs.groupby, ["bar"]);
|
||||
case 2:
|
||||
return assert.deepEqual(kwargs.groupby, ["m2m"]);
|
||||
case 3:
|
||||
return assert.deepEqual(kwargs.groupby, ["bar"]);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
assert.hasClass(target.querySelector(".o_list_renderer table"), "o_list_table_grouped");
|
||||
assert.containsN(target, ".o_group_header", 2);
|
||||
|
||||
await groupByMenu(target, "m2m");
|
||||
assert.containsN(target, ".o_group_header", 4);
|
||||
|
||||
await toggleMenuItem(target, "M2M field");
|
||||
assert.containsN(target, ".o_group_header", 2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
<!-- Allows to take a custom View widget for handling -->
|
||||
<rng:optional><rng:attribute name="js_class"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="default_order"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="default_group_by"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="decoration-bf"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="decoration-it"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="decoration-danger"/></rng:optional>
|
||||
|
||||
Reference in New Issue
Block a user