From ecb41753b66ef562ffdc570d7930b6a6c627925d Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 23 Aug 2023 08:30:43 +0000 Subject: [PATCH] [FIX] web: add record in list with sample data: no flickering Have an editable list view with sample data (sample="1" and no record). Before this commit, there was a flickering when the user clicked on "New" to add a record. Indeed, the list was first re-rendered without the sample mode (i.e. without the opacity style and no content helper), but still with the sample records. With this commit, we wait for the reload to be done before leaving the sample mode, s.t. when the list is re-rendered, we don't have sample records anymore. Part-of: odoo/odoo#132802 --- .../model/relational_model/dynamic_list.js | 4 +- .../web/static/tests/views/list_view_tests.js | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/model/relational_model/dynamic_list.js b/addons/web/static/src/model/relational_model/dynamic_list.js index b414ffcd731..9e05d9264ac 100644 --- a/addons/web/static/src/model/relational_model/dynamic_list.js +++ b/addons/web/static/src/model/relational_model/dynamic_list.js @@ -210,10 +210,10 @@ export class DynamicList extends DataPoint { return unlinked; } - _leaveSampleMode() { + async _leaveSampleMode() { if (this.model.useSampleModel) { + await this._load(this.offset, this.limit, this.orderBy, this.domain); this.model.useSampleModel = false; - return this._load(this.offset, this.limit, this.orderBy, this.domain); } } diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js index 45eefc1c77b..f755ea475e1 100644 --- a/addons/web/static/tests/views/list_view_tests.js +++ b/addons/web/static/tests/views/list_view_tests.js @@ -19407,6 +19407,7 @@ QUnit.module("Views", (hooks) => { assert.strictEqual(input, document.activeElement); assert.strictEqual(input.value, "Value 1"); }); + QUnit.test("monetary field display for rtl languages", async function (assert) { patchWithCleanup(localization, { direction: "rtl", @@ -19442,4 +19443,40 @@ QUnit.module("Views", (hooks) => { "Monetary cells should have ltr direction" ); }); + + QUnit.test("add record in editable list view with sample data", async function (assert) { + serverData.models.foo.records = []; + let def; + await makeView({ + type: "list", + resModel: "foo", + serverData, + arch: '', + noContentHelp: "click to add a record", + mockRPC(route, args) { + if (args.method === "unity_web_search_read") { + return def; + } + }, + }); + + assert.containsOnce(target, ".o_view_sample_data"); + assert.containsOnce(target, ".o_view_nocontent"); + assert.containsN(target, ".o_data_row", 10); + + def = makeDeferred(); + await clickAdd(); + + assert.containsOnce(target, ".o_view_sample_data"); + assert.containsOnce(target, ".o_view_nocontent"); + assert.containsN(target, ".o_data_row", 10); + + def.resolve(); + await nextTick(); + + assert.containsNone(target, ".o_view_sample_data"); + assert.containsNone(target, ".o_view_nocontent"); + assert.containsOnce(target, ".o_data_row"); + assert.containsOnce(target, ".o_data_row.o_selected_row"); + }); });