* Read records.
*
* @param {Array} ids identifiers of the records to read
- * @param {Array} fields fields to read and return, by default all fields are returned
+ * @param {Array} [fields] fields to read and return, by default all fields are returned
+ * @param {Object} [options]
* @returns {$.Deferred}
*/
read_ids: function (ids, fields, options) {
return $.Deferred().resolve([]);
options = options || {};
- // TODO: reorder results to match ids list
return this._model.call('read',
- [ids, fields || false],
- {context: this.get_context(options.context)});
+ [ids, fields || false],
+ {context: this.get_context(options.context)})
+ .then(function (records) {
+ if (records.length <= 1) { return records; }
+ var indexes = {};
+ for (var i = 0; i < ids.length; i++) {
+ indexes[ids[i]] = i;
+ }
+ records.sort(function (a, b) {
+ return indexes[a.id] - indexes[b.id];
+ });
+ return records;
+ });
},
/**
* Read a slice of the records represented by this DataSet, based on its
+openerp.testing.section('data.dataset', {
+ rpc: 'mock',
+ dependencies: ['web.data'],
+}, function (test) {
+ test('read_ids', {asserts: 2}, function (instance, _, mock) {
+ var d = new instance.web.DataSet(null, 'foo');
+ mock('foo:read', function (args) {
+ var ids = args[0];
+ deepEqual(ids, [3, 1, 2]);
+ return [
+ {id: 1, a: 'bar'},
+ {id: 2, a: 'baz'},
+ {id: 3, a: 'foo'}
+ ];
+ });
+
+ return d.read_ids([3, 1, 2]).then(function (records) {
+ deepEqual(
+ records,
+ [
+ {id: 3, a: 'foo'},
+ {id: 1, a: 'bar'},
+ {id: 2, a: 'baz'}
+ ]
+ )
+ });
+ })
+});
+
openerp.testing.section('data.model.group_by', {
rpc: 'mock',
dependencies: ['web.data'],