From c5bf53682e159343ee0c707f6d7f2da972d6add2 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 29 Aug 2017 11:57:33 +0200 Subject: [PATCH] [FIX] web: prevent 'load' event from being handled twice In grouped list view, when a pager is clicked inside a group, a 'load' event is triggered to reload the data with the new offset. The event is handled by the list's controller. However, when the list is in the modal, the event must be stop propagated by the controller of the modal, so that it doesn't go up to the controller of the view displayed behind the modal. It happens for example by reproducing the following steps: - go to Lunch - add a line - search more products - group by vendor in the modal - unfold a group - click on the pager (the group must contain more than 80 records) Before this rev., it crashed because the controller of the form view tried to handle the event. --- .../src/js/views/field_manager_mixin.js | 1 + .../tests/fields/relational_fields_tests.js | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/addons/web/static/src/js/views/field_manager_mixin.js b/addons/web/static/src/js/views/field_manager_mixin.js index 1ee7bf4a501..aaf7e4a5859 100644 --- a/addons/web/static/src/js/views/field_manager_mixin.js +++ b/addons/web/static/src/js/views/field_manager_mixin.js @@ -120,6 +120,7 @@ var FieldManagerMixin = { */ _onLoad: function (event) { var self = this; + event.stopPropagation(); // prevent other field managers from handling this request var data = event.data; if (!data.on_success) { return; } var params = {}; diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 92a24066408..e211d120fe2 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -6885,6 +6885,71 @@ QUnit.module('relational_fields', { list.destroy(); }); + QUnit.test('search more in many2one: group and use the pager', function (assert) { + assert.expect(2); + + this.data.partner.records.push({ + id: 5, + display_name: "Partner 4", + }, { + id: 6, + display_name: "Partner 5", + }, { + id: 7, + display_name: "Partner 6", + }, { + id: 8, + display_name: "Partner 7", + }, { + id: 9, + display_name: "Partner 8", + }, { + id: 10, + display_name: "Partner 9", + }); + + this.data.partner.fields.datetime.searchable = true; + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '
', + + res_id: 1, + archs: { + 'partner,false,list': '', + 'partner,false,search': '' + + ' ' + + '', + }, + viewOptions: { + mode: 'edit', + }, + }); + + var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); + form.$('.o_field_many2one input').click(); + $dropdown.find('.o_m2o_dropdown_option:contains(Search)').mouseenter().click(); // Open Search More + + $('.modal .o_searchview_more').click(); // Magnifying class for more filters + $('.modal .o_search_options .o_group_by_menu a:contains(Bar)').click(); // group by 'Bar' + + $('.modal .o_group_header:first').click(); + assert.strictEqual($('.modal tbody:nth(1) .o_data_row').length, 7, + "should display 7 records in the first page"); + $('.modal .o_group_header:first .o_pager_next').click(); + assert.strictEqual($('.modal tbody:nth(1) .o_data_row').length, 1, + "should display 1 record in the second page"); + + form.destroy(); + }); + QUnit.test('field many2many_tags keeps focus when being edited', function (assert) { assert.expect(7);