[FIX] web: kanban: read more is briefly shown when quick create

Before this commit, when quick creating a new record in a kanban view,
the "read more" button is briefly shown (flickering). This issue occurs
because, when creating a new record, we increment the number of records
in the group before adding the record to the list of displayed records.
This means that for a brief moment the number of records of the group is
bigger than the number of displayed records, therefore the "load more"
button is show.

Note that this flickering was introduced due to the following
refactoring : https://github.com/odoo/odoo/commit/067bcac53336b5f66f695b1c10b333d8c722225d

Now, we increment the number of records on the group after we added the
record to the displayed records' list.

closes odoo/odoo#119142

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Jorge Pinna Puissant
2023-04-20 10:52:06 +02:00
parent c741bbb4a3
commit 95c7031027
2 changed files with 50 additions and 3 deletions
@@ -2406,7 +2406,10 @@ export class DynamicGroupList extends DynamicList {
async _loadGroups() {
const firstGroupByName = this.firstGroupBy.split(":")[0];
const _orderBy = this.orderBy.filter(
(o) => o.name === firstGroupByName || (this.fieldNames.includes(o.name) && this.fields[o.name].group_operator !== undefined)
(o) =>
o.name === firstGroupByName ||
(this.fieldNames.includes(o.name) &&
this.fields[o.name].group_operator !== undefined)
);
const orderby = orderByToString(_orderBy);
const { groups, length } = await this.model.orm.webReadGroup(
@@ -2597,9 +2600,10 @@ export class Group extends DataPoint {
return this.list.addRecord(record, index);
}
addExistingRecord(resId, atFirstPosition = false) {
async addExistingRecord(resId, atFirstPosition = false) {
const record = await this.list.addExistingRecord(resId, atFirstPosition);
this.count++;
return this.list.addExistingRecord(resId, atFirstPosition);
return record;
}
createRecord(params = {}, atFirstPosition = false) {
@@ -1849,6 +1849,49 @@ QUnit.module("Views", (hooks) => {
assert.containsOnce(target, ".o_kanban_group:first-child .o_kanban_quick_create");
});
QUnit.test("quick create record flickering (load more)", async (assert) => {
let def;
serverData.views["partner,some_view_ref,form"] = `
<form>
<field name="foo"/>
</form>`;
await makeView({
type: "kanban",
resModel: "partner",
serverData,
arch: `
<kanban on_create="quick_create" quick_create_view="some_view_ref">
<field name="bar"/>
<templates>
<t t-name="kanban-box">
<div>
<field name="foo"/>
</div>
</t>
</templates>
</kanban>`,
groupBy: ["bar"],
async mockRPC(route, args) {
if (args.method === "read") {
await def;
}
},
});
// click on 'Create' -> should open the quick create in the first column
await createRecord();
// fill the quick create and validate
await editQuickCreateInput("foo", "new partner");
def = makeDeferred();
await validateRecord();
assert.containsNone(target, ".o_kanban_load_more");
def.resolve();
await nextTick();
assert.containsNone(target, ".o_kanban_load_more");
});
QUnit.test(
"quick create record should focus default field [REQUIRE FOCUS]",
async function (assert) {