[FIX] web: sort x2m on multi fields

Before this commit, go to a form view with an x2m displayed in list mode.
If you sort the x2m on two differents fields, a crash is displayed.

How to reproduce:
- Go to a form view with an x2m in list mode with at least 2 columns sortable.
- Click on a column to order
- Click on a second column to order

Before this commit:
    We have a crash

After this commit:
    The list is ordered correctly

Part-of: odoo/odoo#114024
This commit is contained in:
FrancoisGe
2023-07-24 20:17:50 +02:00
committed by Aaron Bohy
parent 218ad8456a
commit 5987e95ec2
2 changed files with 28 additions and 15 deletions
@@ -27,7 +27,7 @@ function compareRecords(r1, r2, orderBy, fields) {
return 1;
}
if (orderBy.length > 1) {
return compareRecords(r1, r2, orderBy.slice(1));
return compareRecords(r1, r2, orderBy.slice(1), fields);
}
return 0;
}
@@ -2885,9 +2885,9 @@ QUnit.module("Fields", (hooks) => {
QUnit.test("sorting one2many fields", async function (assert) {
serverData.models.partner.fields.foo.sortable = true;
serverData.models.partner.records.push({ id: 23, foo: "abc" });
serverData.models.partner.records.push({ id: 24, foo: "xyz" });
serverData.models.partner.records.push({ id: 25, foo: "def" });
serverData.models.partner.records.push({ id: 23, foo: "abc", int_field: 1 });
serverData.models.partner.records.push({ id: 24, foo: "xyz", int_field: 1 });
serverData.models.partner.records.push({ id: 25, foo: "def", int_field: 2 });
serverData.models.partner.records[0].p = [23, 24, 25];
let rpcCount = 0;
@@ -2900,6 +2900,7 @@ QUnit.module("Fields", (hooks) => {
<field name="p">
<tree>
<field name="foo"/>
<field name="int_field"/>
</tree>
</field>
</form>`,
@@ -2910,22 +2911,34 @@ QUnit.module("Fields", (hooks) => {
});
rpcCount = 0;
assert.strictEqual(
[...target.querySelectorAll(".o_data_cell")].map((c) => c.textContent).join(" "),
"abc xyz def"
assert.deepEqual(
[...target.querySelectorAll(".o_data_cell[name='foo']")].map((c) => c.textContent),
["abc", "xyz", "def"]
);
await click(target.querySelector("table thead .o_column_sortable"));
await click(target.querySelector("table thead [data-name='foo'].o_column_sortable"));
assert.strictEqual(rpcCount, 0, "in memory sort, no RPC should have been done");
assert.strictEqual(
[...target.querySelectorAll(".o_data_cell")].map((c) => c.textContent).join(" "),
"abc def xyz"
assert.deepEqual(
[...target.querySelectorAll(".o_data_cell[name='foo']")].map((c) => c.textContent),
["abc", "def", "xyz"]
);
await click(target.querySelector("table thead .o_column_sortable"));
assert.strictEqual(
[...target.querySelectorAll(".o_data_cell")].map((c) => c.textContent).join(" "),
"xyz def abc"
await click(target.querySelector("table thead [data-name='foo'].o_column_sortable"));
assert.deepEqual(
[...target.querySelectorAll(".o_data_cell[name='foo']")].map((c) => c.textContent),
["xyz", "def", "abc"]
);
await click(target.querySelector("table thead [data-name='int_field'].o_column_sortable"));
assert.deepEqual(
[...target.querySelectorAll(".o_data_cell[name='foo']")].map((c) => c.textContent),
["xyz", "abc", "def"]
);
await click(target.querySelector("table thead [data-name='int_field'].o_column_sortable"));
assert.deepEqual(
[...target.querySelectorAll(".o_data_cell[name='foo']")].map((c) => c.textContent),
["def", "xyz", "abc"]
);
});