[FIX] web: limit fetched records when grouping

**Issue:**

- Open a list view with `expand="1"` and `limit=<arbitrary small number, say 5>`.
- BUG: The pager shows that it's displaying the limited records, but in reality,
  it's displaying all records under each group.

**Solution:**

This is because we are *not* limiting the number of records being fetch in the first
read_group rpc. We are now specifying the expand_limit in this commit.

closes odoo/odoo#106238

X-original-commit: e5bba9f5eb63ee95924c892801fe18feaef6d1fc
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
This commit is contained in:
Joseph Caburnay
2022-11-22 16:06:04 +01:00
parent c4d6984641
commit cd3af17a27
3 changed files with 32 additions and 1 deletions
@@ -2399,6 +2399,7 @@ export class DynamicGroupList extends DynamicList {
lazy: true,
expand: this.expand,
expand_orderby: this.expand ? orderByToString(this.orderBy) : null,
expand_limit: this.expand ? this.limitByGroup : null,
offset: this.offset,
limit: this.limit,
context: this.context,
@@ -12,7 +12,7 @@ import { session } from "@web/session";
import { FloatField } from "@web/views/fields/float/float_field";
import { TextField } from "@web/views/fields/text/text_field";
import { ListController } from "@web/views/list/list_controller";
import { DynamicRecordList } from "@web/views/relational_model";
import { DynamicRecordList, DynamicGroupList } from "@web/views/relational_model";
import { actionService } from "@web/webclient/actions/action_service";
import { makeFakeLocalizationService, makeFakeUserService } from "../helpers/mock_services";
import { Many2XAutocomplete } from "@web/views/fields/relational_utils";
@@ -5377,6 +5377,35 @@ QUnit.module("Views", (hooks) => {
}
);
QUnit.test(
"grouped, show only limited records when the list view is initially expanded",
async function (assert) {
const forcedDefaultLimit = 3;
patchWithCleanup(DynamicGroupList, { DEFAULT_LIMIT: forcedDefaultLimit });
serverData.models.foo.records = [
{ id: 121, foo: "blip" },
{ id: 122, foo: "blip" },
{ id: 123, foo: "blip" },
{ id: 124, foo: "blip" },
{ id: 125, foo: "blip" },
{ id: 126, foo: "blip" },
];
await makeView({
type: "list",
resModel: "foo",
serverData,
arch: /*xml*/ `
<tree expand="1">
<field name="foo"/>
</tree>`,
groupBy: ["foo"],
});
assert.containsN(target, ".o_data_row", forcedDefaultLimit);
}
);
QUnit.test("list keeps offset on switchView", async (assert) => {
assert.expect(3);
serverData.views = {
@@ -127,6 +127,7 @@ QUnit.module("ViewDialogs", (hooks) => {
orderby: "",
expand: false,
expand_orderby: null,
expand_limit: null,
lazy: true,
limit: 80,
offset: 0,