From c2563dbb0d84f28e76bd5b17e5d842383e3434ca Mon Sep 17 00:00:00 2001 From: Adrien Dieudonne Date: Mon, 28 Aug 2017 09:15:15 +0200 Subject: [FIX] web: BasicModel: correctly sort editable lists This rev. fixes several issues with the sorting of dataPoints of type list in the BasicModel. First, only 'static' lists (i.e. x2many lists) must be sorted client-side, and results of search_read RPCs must remain unsorted as they are already retrieved sorted from the server. Second, editable and non-editable x2many lists don't behave the same with respect to sorting (we reproduced in this commit the behavior of saas-15). With editable lists, the edited rows are unsorted, except if the user explicitely ask for a sort (by clicking on a column header), until the form view is saved. With non-editable lists (as for x2many kanban), the sort is performed directly when a record is created or updated (as the edition is done from a dialog). --- addons/web/static/tests/views/basic_model_tests.js | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'addons/web/static/tests/views/basic_model_tests.js') diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js index 318b715a504..b2a00f1ca09 100644 --- a/addons/web/static/tests/views/basic_model_tests.js +++ b/addons/web/static/tests/views/basic_model_tests.js @@ -2086,4 +2086,38 @@ QUnit.module('Views', { model.destroy(); }); + QUnit.test('only x2many lists (static) should be sorted client-side', function (assert) { + assert.expect(1); + + this.params.modelName = 'partner_type'; + this.params.res_id = undefined; + this.params.orderedBy = [{name: 'display_name', asc: true}]; + + var model = createModel({ + Model: BasicModel, + data: this.data, + mockRPC: function (route) { + if (route === '/web/dataset/search_read') { + // simulate randomn sort form the server + return $.when({ + length: 3, + records: [ + {id: 12, display_name: "gold", date: "2017-01-25"}, + {id: 15, display_name: "bronze"}, + {id: 14, display_name: "silver"}, + ], + }); + } + return this._super.apply(this, arguments); + }, + }); + + model.load(this.params).then(function (resultID) { + var list = model.get(resultID); + assert.deepEqual(_.map(list.data, 'res_id'), [12, 15, 14], + "should have kept the order from the server"); + }); + model.destroy(); + }); + });}); -- cgit v1.2.3