summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/views
diff options
context:
space:
mode:
authorJérémy Hennecart <jeh@odoo.com>2020-07-22 07:31:08 +0000
committerThibault Delavallée <tde@odoo.com>2020-08-18 08:56:48 +0000
commit2c21301d314e4fd7c16ac88162786c096e9d80bd (patch)
tree4fecb868d6327748682b7fc3bf2c2352c7d74733 /addons/web/static/tests/views
parent29b44207c9d59473c9532713aed20b01f6a36d0e (diff)
[IMP] web: manage invisible fields in graph and pivot view
PURPOSE Be able to remove some measures from graph / pivot views. Currently fields are automatically added but some of them make no sense. SPECIFICATIONS Add the possibility to not display some fields in the measures dropdown for the graph and pivot views. When a field is not displayed in the measures of a pivot views we remove them also from the list of groupable fields. LINKS Task ID-2288381 Community PR #54774 Enterprise PR odoo/enterprise#11970 Upgrade PR odoo/upgrade#1519
Diffstat (limited to 'addons/web/static/tests/views')
-rw-r--r--addons/web/static/tests/views/graph_tests.js54
-rw-r--r--addons/web/static/tests/views/pivot_tests.js5
2 files changed, 52 insertions, 7 deletions
diff --git a/addons/web/static/tests/views/graph_tests.js b/addons/web/static/tests/views/graph_tests.js
index 253c98d706a..fda4c5cb190 100644
--- a/addons/web/static/tests/views/graph_tests.js
+++ b/addons/web/static/tests/views/graph_tests.js
@@ -97,16 +97,17 @@ QUnit.module('Views', {
product_id: {string: "Product", type: "many2one", relation: 'product', store: true},
color_id: {string: "Color", type: "many2one", relation: 'color'},
date: {string: "Date", type: 'date', store: true, sortable: true},
+ revenue: {string: "Revenue", type: 'integer', store: true},
},
records: [
- {id: 1, foo: 3, bar: true, product_id: 37, date: "2016-01-01"},
- {id: 2, foo: 53, bar: true, product_id: 37, color_id: 7, date: "2016-01-03"},
- {id: 3, foo: 2, bar: true, product_id: 37, date: "2016-03-04"},
- {id: 4, foo: 24, bar: false, product_id: 37, date: "2016-03-07"},
- {id: 5, foo: 4, bar: false, product_id: 41, date: "2016-05-01"},
+ {id: 1, foo: 3, bar: true, product_id: 37, date: "2016-01-01", revenue: 1},
+ {id: 2, foo: 53, bar: true, product_id: 37, color_id: 7, date: "2016-01-03", revenue: 2},
+ {id: 3, foo: 2, bar: true, product_id: 37, date: "2016-03-04", revenue: 3},
+ {id: 4, foo: 24, bar: false, product_id: 37, date: "2016-03-07", revenue: 4},
+ {id: 5, foo: 4, bar: false, product_id: 41, date: "2016-05-01", revenue: 5},
{id: 6, foo: 63, bar: false, product_id: 41},
{id: 7, foo: 42, bar: false, product_id: 41},
- {id: 8, foo: 48, bar: false, product_id: 41, date: "2016-04-01"},
+ {id: 8, foo: 48, bar: false, product_id: 41, date: "2016-04-01", revenue: 8},
]
},
product: {
@@ -1216,6 +1217,47 @@ QUnit.module('Views', {
graph.destroy();
});
+ QUnit.test('graph view without invisible attribute on field', async function (assert) {
+ assert.expect(4);
+
+ const graph = await createView({
+ View: GraphView,
+ model: "foo",
+ data: this.data,
+ arch: `<graph string="Partners"></graph>`,
+ });
+
+ await testUtils.dom.click(graph.$('.btn-group:first button'));
+ assert.containsN(graph, 'li.o_menu_item', 3,
+ "there should be three menu item in the measures dropdown (count, revenue and foo)");
+ assert.containsOnce(graph, 'li.o_menu_item a:contains("Revenue")');
+ assert.containsOnce(graph, 'li.o_menu_item a:contains("Foo")');
+ assert.containsOnce(graph, 'li.o_menu_item a:contains("Count")');
+
+ graph.destroy();
+ });
+
+ QUnit.test('graph view with invisible attribute on field', async function (assert) {
+ assert.expect(2);
+
+ const graph = await createView({
+ View: GraphView,
+ model: "foo",
+ data: this.data,
+ arch: `
+ <graph string="Partners">
+ <field name="revenue" invisible="1"/>
+ </graph>`,
+ });
+
+ await testUtils.dom.click(graph.$('.btn-group:first button'));
+ assert.containsN(graph, 'li.o_menu_item', 2,
+ "there should be only two menu item in the measures dropdown (count and foo)");
+ assert.containsNone(graph, 'li.o_menu_item a:contains("Revenue")');
+
+ graph.destroy();
+ });
+
QUnit.test('graph view sort by measure', async function (assert) {
assert.expect(18);
diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js
index 48e67e8641e..026741ac682 100644
--- a/addons/web/static/tests/views/pivot_tests.js
+++ b/addons/web/static/tests/views/pivot_tests.js
@@ -192,7 +192,7 @@ QUnit.module('Views', {
});
QUnit.test('pivot rendering with invisible attribute on field', async function (assert) {
- assert.expect(2);
+ assert.expect(3);
// when invisible, a field should neither be an active measure,
// nor be a selectable measure.
_.extend(this.data.partner.fields, {
@@ -214,6 +214,9 @@ QUnit.module('Views', {
assert.containsOnce(pivot, '.o_pivot_measure_row');
// there should be only one measure besides count, as the other one is invisible
assert.containsN(pivot, '.o_cp_bottom_left .dropdown-item', 2);
+ // the invisible field souldn't be in the groupable fields neither
+ await testUtils.dom.click(pivot.$('.o_pivot_header_cell_closed:first'));
+ assert.containsNone(pivot, '.o_pivot_field_menu a[data-field="foo2"]');
pivot.destroy();
});