diff options
| author | Khoi Nguyen <bng@odoo.com> | 2017-08-09 15:18:35 +0200 |
|---|---|---|
| committer | Khoi Nguyen <bng@odoo.com> | 2017-08-11 17:44:30 +0200 |
| commit | 1e65cd3d4e7ce88004cf0f4d3b537b5a0ff3348b (patch) | |
| tree | 22c78b02054bd8f606515aa93f99e28dc82c4ae5 /addons/web | |
| parent | 5fce37486a707c19ba4c751b234f5620ed066aa7 (diff) | |
[FIX] web: fix traceback when saving fields list during data export
The traceback was caused by an occurence of this.dataset, which was left
out in the new views refactoring (this.dataset has been replaced by
this.record).
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/static/src/js/widgets/data_export.js | 2 | ||||
| -rw-r--r-- | addons/web/static/tests/widgets/data_export_tests.js | 84 |
2 files changed, 85 insertions, 1 deletions
diff --git a/addons/web/static/src/js/widgets/data_export.js b/addons/web/static/src/js/widgets/data_export.js index c11551ca2cc..a94b38f04b9 100644 --- a/addons/web/static/src/js/widgets/data_export.js +++ b/addons/web/static/src/js/widgets/data_export.js @@ -179,7 +179,7 @@ var DataExport = Dialog.extend({ var self = this; this.exports.create({ name: value, - resource: this.dataset.model, + resource: this.record.model, export_fields: _.map(fields, function (field) { return [0, 0, {name: field}]; }), diff --git a/addons/web/static/tests/widgets/data_export_tests.js b/addons/web/static/tests/widgets/data_export_tests.js index 83169a64e1f..d251e3dea15 100644 --- a/addons/web/static/tests/widgets/data_export_tests.js +++ b/addons/web/static/tests/widgets/data_export_tests.js @@ -4,6 +4,7 @@ odoo.define('web.data_export_tests', function (require) { var framework = require('web.framework'); var ListView = require('web.ListView'); var testUtils = require('web.test_utils'); +var data = require('web.data'); var createView = testUtils.createView; @@ -127,6 +128,89 @@ QUnit.module('widgets', { ]); }); + QUnit.test('saving fields list when exporting data', function (assert) { + assert.expect(6); + + var create = data.DataSet.prototype.create; + + data.DataSet.prototype.create = function (data, options) { + assert.step('create'); + return $.when([]); + }; + + var list = createView({ + View: ListView, + model: 'partner', + data: this.data, + arch: '<tree><field name="foo"/></tree>', + viewOptions: { + sidebar: true, + }, + mockRPC: function (route) { + if (route === '/web/export/formats') { + return $.when([ + {tag: 'csv', label: 'CSV'}, + {tag: 'xls', label: 'Excel'}, + ]); + } + if (route === '/web/export/get_fields') { + return $.when([ + { + field_type: "one2many", + string: "Activities", + required: false, + value: "activity_ids/id", + id: "activity_ids", + params: {"model": "mail.activity", "prefix": "activity_ids", "name": "Activities"}, + relation_field: "res_id", + children: true, + }, + ]); + } + return this._super.apply(this, arguments); + }, + }); + + list.getParent().searchview = { + build_search_data: function () { + assert.step('build_search_data'); + return { + contexts: [], + domains: [], + groupbys: [], + }; + }, + }; + + // Open the export modal + list.$('thead th.o_list_record_selector input').click(); + list.sidebar.$('a:contains(Export)').click(); + assert.strictEqual($('.modal').length, 1, + "a modal dialog should be open"); + + // Select 'Activities' in fields to export + assert.strictEqual($('.modal select.o_fields_list option').length, 0, + "the fields list should be empty"); + $('.modal .o_export_tree_item:contains(Activities)').click(); + $('.modal button:contains(Add)').click(); + assert.strictEqual($('.modal select.o_fields_list option').length, 1, + "there should be one item in the fields list"); + + // Save fields list + $('.modal a:contains(Save fields list)').click(); + $('.modal .o_save_list > input').val('fields list').trigger('input'); + $('.modal .o_save_list > button').click(); + assert.verifySteps(['build_search_data', 'create'], + "create should have been called"); + + // Close the modal and destroy list + $('.modal button span:contains(Close)').click(); + list.destroy(); + + // restore create function + data.DataSet.prototype.create = create; + }); + }); }); |
