From a7cbac305ed8645ce8ce67210d2ca5d723a891f0 Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Thu, 10 Jan 2019 13:53:05 +0000 Subject: [FIX] web: reset offset in the search more view dialog Start on the modal obtained by a "search more". The offset is never reset. So suppose you are on page 2, looking at record 81-160. Do a research that gives less than 80 records. The result of the search is nothing, since is has been done with a 80 offset. It should be reset to 0 when we do a new search. opw 1920826 closes odoo/odoo#30109 --- .../static/tests/fields/relational_fields_tests.js | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'addons/web/static/tests/fields/relational_fields_tests.js') diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 3991d499f3d..5d2ab325ef2 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -525,6 +525,61 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('search more pager is reset when doing a new search', function (assert) { + assert.expect(6); + for(var i = 10; i < 180; i++) { + this.data.partner.records.push({ + id: i, + display_name: "Partner " + i, + }); + } + + function stringToEvent ($element, string) { + for (var i = 0; i < string.length; i++) { + var keyAscii = string.charCodeAt(i); + $element.val($element.val()+string[i]); + $element.trigger($.Event('keyup', {which: keyAscii, keyCode:keyAscii})); + } + $element.trigger($.Event('keyup', {which: $.ui.keyCode.ENTER, keyCode:$.ui.keyCode.ENTER})); + } + + this.data.partner.fields.datetime.searchable = true; + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '
', + archs: { + 'partner,false,list': '', + 'partner,false,search': '', + }, + res_id: 1, + }); + + form.$buttons.find('.o_form_button_edit').click(); + 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(); + $('.modal .o_pager_next').click(); + + assert.strictEqual($('.o_pager_limit').text(), "1173", "there should be 173 records"); + assert.strictEqual($('.o_pager_value').text(), "181-160", "should display the second page"); + assert.strictEqual($('tr.o_data_row').length, 80, "should display 80 record"); + + stringToEvent($('.modal .o_searchview_input'), 'first'); + + assert.strictEqual($('.o_pager_limit').text(), "11", "there should be 1 record"); + assert.strictEqual($('.o_pager_value').text(), "11-1", "should display the first page"); + assert.strictEqual($('tr.o_data_row').length, 1, "should display 1 record"); + form.destroy(); + }); + QUnit.test('onchanges on many2ones trigger when editing record in form view', function (assert) { assert.expect(9); -- cgit v1.2.3 From dec9f7c4cec68863c2d4fa82235e3fd2b6def4d5 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 11 Jan 2019 14:36:13 +0000 Subject: [FIX] web: one2many list: quickly switch between pages Before this rev., a crash might occur when the user quickly switched twice between pages (e.g. go to page 2, then page 3) on a slow network. In the given example, when data of page 2 returned, the list was re-rendered. Unfortunately, the offset of that list' datapoint was already changed due to the switch to page 3, meaning that the view tried to render a page that wasn't loaded yet, leading to a crash if there were modifiers to evaluate, or to empty records being displayed. This rev. ensures that the view is rendered with the data of the page it expects. closes odoo/odoo#30150 --- .../static/tests/fields/relational_fields_tests.js | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'addons/web/static/tests/fields/relational_fields_tests.js') diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 5d2ab325ef2..421cee8a4b1 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -10093,6 +10093,48 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('quickly switch between pages in one2many list', function (assert) { + assert.expect(2); + + this.data.partner.records[0].turtles = [1, 2, 3]; + + var readDefs = [$.when(), $.Deferred(), $.Deferred()]; + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '
', + mockRPC: function (route, args) { + var result = this._super.apply(this, arguments); + if (args.method === 'read') { + var recordID = args.args[0][0]; + return $.when(readDefs[recordID - 1]).then(_.constant(result)); + } + return result; + }, + res_id: 1, + }); + + form.$('.o_field_widget[name=turtles] .o_pager_next').click(); + form.$('.o_field_widget[name=turtles] .o_pager_next').click(); + + readDefs[1].resolve(); + + assert.strictEqual(form.$('.o_field_widget[name=turtles] .o_data_cell').text(), 'donatello'); + + readDefs[2].resolve(); + + assert.strictEqual(form.$('.o_field_widget[name=turtles] .o_data_cell').text(), 'raphael'); + + form.destroy(); + }); + QUnit.module('FieldMany2Many'); QUnit.test('many2many kanban: edition', function (assert) { -- cgit v1.2.3