summaryrefslogtreecommitdiff
path: root/addons/web
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-05-29 14:09:18 +0200
committerGéry Debongnie <ged@odoo.com>2017-05-29 16:20:45 +0200
commit5788ee8a1cc903431b100a3861686cfa606aa620 (patch)
tree9b43cb850aecf13f410d7418de66c4fdde6f9730 /addons/web
parent0bb3f21964219073a261b493a2d24560609987c3 (diff)
[FIX] web: prevent crash when exporting all data
In the list controller, some code to determine the active domain to export was causing a crash. It was easy to see: just select all records in a list view, then click on 'Export' in the sidebar. Note that the data_export code is still quite old, and did evolve organically. It does not conform to our new design principles, in particular, the way component should communicate. But this is a task for another day.
Diffstat (limited to 'addons/web')
-rw-r--r--addons/web/static/src/js/views/list/list_controller.js3
-rw-r--r--addons/web/static/src/js/widgets/data_export.js5
-rw-r--r--addons/web/static/tests/widgets/data_export_tests.js132
-rw-r--r--addons/web/views/webclient_templates.xml1
4 files changed, 139 insertions, 2 deletions
diff --git a/addons/web/static/src/js/views/list/list_controller.js b/addons/web/static/src/js/views/list/list_controller.js
index 815ac0497a2..3c86b7c222f 100644
--- a/addons/web/static/src/js/views/list/list_controller.js
+++ b/addons/web/static/src/js/views/list/list_controller.js
@@ -92,7 +92,8 @@ var ListController = BasicController.extend({
contexts: [userContext].concat(searchData.contexts),
group_by_seq: searchData.groupbys || []
});
- return $.when(self.dataset.domain.concat(results.domain || []));
+ var record = self.model.get(self.handle, {raw: true});
+ return $.when(record.getDomain().concat(results.domain || []));
} else {
return $.Deferred().resolve();
}
diff --git a/addons/web/static/src/js/widgets/data_export.js b/addons/web/static/src/js/widgets/data_export.js
index 13ab8fd0892..c11551ca2cc 100644
--- a/addons/web/static/src/js/widgets/data_export.js
+++ b/addons/web/static/src/js/widgets/data_export.js
@@ -295,7 +295,10 @@ var DataExport = Dialog.extend({
}
var self = this;
- return this.exports.read_slice(['name'], {
+ return this._rpc({
+ model: 'ir.exports',
+ method: 'search_read',
+ fields: ['name'],
domain: [['resource', '=', this.record.model]]
}).then(function (export_list) {
if (!export_list.length) {
diff --git a/addons/web/static/tests/widgets/data_export_tests.js b/addons/web/static/tests/widgets/data_export_tests.js
new file mode 100644
index 00000000000..83169a64e1f
--- /dev/null
+++ b/addons/web/static/tests/widgets/data_export_tests.js
@@ -0,0 +1,132 @@
+odoo.define('web.data_export_tests', function (require) {
+"use strict";
+
+var framework = require('web.framework');
+var ListView = require('web.ListView');
+var testUtils = require('web.test_utils');
+
+var createView = testUtils.createView;
+
+QUnit.module('widgets', {
+ beforeEach: function () {
+ this.data = {
+ partner: {
+ fields: {
+ foo: {string: "Foo", type: "char"},
+ },
+ records: [
+ {
+ id: 1,
+ foo: "yop",
+ },
+ ]
+ },
+ 'ir.exports': {
+ fields: {
+ name: {string: "Name", type: "char"},
+ },
+ records: [],
+ },
+ };
+ }
+}, function () {
+
+ QUnit.module('Data Export');
+
+
+ QUnit.test('exporting all data in list view', function (assert) {
+ assert.expect(7);
+
+ var blockUI = framework.blockUI;
+ var unblockUI = framework.unblockUI;
+ framework.blockUI = function () {
+ assert.step('block UI');
+ };
+ framework.unblockUI = function () {
+ assert.step('unblock UI');
+ };
+
+ 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,
+ }, {
+ children: false,
+ field_type: 'text',
+ id: "note",
+ relation_field: null,
+ required: false,
+ string: 'Description',
+ value: "note",
+ }
+ ]);
+ }
+ return this._super.apply(this, arguments);
+ },
+ session: {
+ get_file: function (params) {
+ assert.step(params.url);
+ params.complete();
+ },
+ },
+ });
+
+ list.getParent().searchview = {
+ build_search_data: function () {
+ assert.step('build_search_data');
+ return {
+ contexts: [],
+ domains: [],
+ groupbys: [],
+ };
+ },
+ };
+ 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");
+ assert.strictEqual($('span.o_tree_column:contains(Activities)').length, 1,
+ "the Activities field should be in the list of exportable fields");
+
+ // select the field Description, click on add, then export and close
+ $('.modal span:contains(Description)').click();
+ $('.modal .o_add_field').click();
+ $('.modal span:contains(Export To File)').click();
+ $('.modal span:contains(Close)').click();
+
+ list.destroy();
+ framework.blockUI = blockUI;
+ framework.unblockUI = unblockUI;
+ assert.verifySteps([
+ 'build_search_data',
+ 'block UI',
+ '/web/export/csv',
+ 'unblock UI',
+ ]);
+ });
+
+});
+
+});
diff --git a/addons/web/views/webclient_templates.xml b/addons/web/views/webclient_templates.xml
index 57dc97d3ae7..5a517e82f21 100644
--- a/addons/web/views/webclient_templates.xml
+++ b/addons/web/views/webclient_templates.xml
@@ -453,6 +453,7 @@
<script type="text/javascript" src="/web/static/tests/chrome/search_tests.js"></script>
<script type="text/javascript" src="/web/static/tests/chrome/pager_tests.js"></script>
+ <script type="text/javascript" src="/web/static/tests/widgets/data_export_tests.js"/>
<script type="text/javascript" src="/web/static/tests/widgets/domain_selector_tests.js"/>
<script type="text/javascript" src="/web/static/tests/widgets/model_field_selector_tests.js"/>