summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2020-09-03 07:20:20 +0000
committerAaron Bohy <aab@odoo.com>2020-09-04 13:14:46 +0000
commita5ab687be4e7890262ce9429e18dd011021513d5 (patch)
tree98ef2192847f8b59adf6063b2f962a1cddac187c
parent96a8a4aad70c6ff1c53a7f4919fc1aad3039f5ab (diff)
[FIX] web: list: do not call on_attach_callback at reload
Before this commit, the ListRenderer's on_attach_callback hook was called each time the view was reloaded, even though the renderer was already in the DOM. As a consequence, sub components were mounted several times, which could lead to issues. For instance, go to Inventory > Operations > Transfers, create a new one. Change the Operation Type to a Receipt, and change again to a Delivery: it crashed. Task 2315149 Closes #56701 closes odoo/odoo#57099 X-original-commit: 78f361fb5382e4c7aed9a4e705e20f8d8757300d Signed-off-by: Julien Mougenot (jum) <jum@odoo.com> Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
-rw-r--r--addons/web/static/src/js/views/list/list_renderer.js8
-rw-r--r--addons/web/static/tests/views/list_tests.js25
2 files changed, 29 insertions, 4 deletions
diff --git a/addons/web/static/src/js/views/list/list_renderer.js b/addons/web/static/src/js/views/list/list_renderer.js
index 05481cd9556..4571b1275a4 100644
--- a/addons/web/static/src/js/views/list/list_renderer.js
+++ b/addons/web/static/src/js/views/list/list_renderer.js
@@ -1090,10 +1090,10 @@ var ListRenderer = BasicRenderer.extend({
// append the table (if any) to the main element
if (tableWrapper) {
- dom.append(this.el, tableWrapper, {
- callbacks: [{ widget: this }],
- in_DOM: document.body.contains(this.el),
- });
+ this.el.appendChild(tableWrapper);
+ if (document.body.contains(this.el)) {
+ this.pagers.forEach(pager => pager.on_attach_callback());
+ }
if (this.optionalColumns.length) {
this.el.classList.add('o_list_optional_columns');
this.$('table').append(
diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js
index a0cd91774ce..4d8cf86460e 100644
--- a/addons/web/static/tests/views/list_tests.js
+++ b/addons/web/static/tests/views/list_tests.js
@@ -162,6 +162,31 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('on_attach_callback is properly called', async function (assert) {
+ assert.expect(3);
+
+ testUtils.mock.patch(ListRenderer, {
+ on_attach_callback() {
+ assert.step('on_attach_callback');
+ this._super(...arguments);
+ },
+ });
+
+ const list = await createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree><field name="display_name"/></tree>',
+ });
+
+ assert.verifySteps(['on_attach_callback']);
+ await list.reload();
+ assert.verifySteps([]);
+
+ testUtils.mock.unpatch(ListRenderer);
+ list.destroy();
+ });
+
QUnit.test('list with create="0"', async function (assert) {
assert.expect(2);