[FIX] web: Allow users to enable list view with group_by_no_leaf

- Go to accounting/Report/Invoices Analysis
- Open studio
- enable list view
- empty view

This code bellow compute count_field as `__count` because group_by_no_leaf
is in the context.

But in the basic_model we don't consider this case.

https://github.com/odoo/odoo/blob/5797fd80a63309269f15bcbe4948d4429a53eec2/odoo/models.py#L2798-L2802

opw-2980923

closes odoo/odoo#101570

X-original-commit: bde2985959ef8914da4b8aca96efc5772262d0c0
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Achraf
2022-09-29 13:23:01 +02:00
parent 43908c5fcd
commit c120f43905
3 changed files with 35 additions and 1 deletions
@@ -2401,6 +2401,10 @@ export class DynamicGroupList extends DynamicList {
}
break;
}
// When group_by_no_leaf key is present FIELD_ID_count doesn't exist
// we have to get the count from `__count` instead
// see _read_group_raw in models.py
case `__count`:
case `${groupByField.name}_count`: {
groupParams.count = value;
break;
@@ -1095,7 +1095,13 @@ export class MockServer {
delete group.__range;
}
// compute count key to match dumb server logic...
const countKey = kwargs.lazy ? groupBy[0].split(":")[0] + "_count" : "__count";
const groupByNoLeaf = kwargs.context ? "group_by_no_leaf" in kwargs.context : false;
let countKey;
if (kwargs.lazy && (groupBy.length >= 2 || !groupByNoLeaf)) {
countKey = groupBy[0].split(":")[0] + "_count";
} else {
countKey = "__count";
}
group[countKey] = groupRecords.length;
aggregateFields(group, groupRecords);
readGroupResult.push(group);
@@ -15151,4 +15151,28 @@ QUnit.module("Views", (hooks) => {
await pagerPrevious(target);
assert.deepEqual([...getPagerValue(target), getPagerLimit(target)], [1, 2]);
});
QUnit.test("list with group_by_no_leaf and group by", async function (assert) {
assert.expect(4);
await makeView({
type: "list",
resModel: "foo",
serverData,
arch: '<tree expand="1"><field name="foo"/></tree>',
groupBy: ["currency_id"],
context: { group_by_no_leaf: true },
});
const groups = target.querySelectorAll(".o_group_name");
const groupsRecords = [...target.querySelectorAll(".o_data_row .o_data_cell")];
assert.strictEqual(groups.length, 2, "There should be 2 groups");
assert.strictEqual(groups[0].textContent, "USD (3) ", "Second group should have 3 records");
assert.strictEqual(groups[1].textContent, "EUR (1) ", "First group should have 1 record");
assert.deepEqual(
groupsRecords.map((groupEl) => groupEl.textContent),
["blip", "gnap", "blip", "yop"],
"Groups should contains correct records"
);
});
});