summaryrefslogtreecommitdiff
path: root/addons/web
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-03-21 13:58:37 +0100
committerChristophe Simonis <chs@odoo.com>2019-03-21 13:58:37 +0100
commit4eff0af02ef2c182793fce5f32d2d15f53a5fba7 (patch)
tree8790e0051f631240562a9408ccd5e2a5cd64782b /addons/web
parent45e3e432a3621cf03a38ce48562eb967f1ff76e0 (diff)
parent6878c9f3424f27df9b07a665f9c0f5ef6e254996 (diff)
[MERGE] forward port branch saas-12.1 up to 6878c9f3424
Diffstat (limited to 'addons/web')
-rw-r--r--addons/web/static/lib/qweb/qweb2.js2
-rw-r--r--addons/web/static/src/js/views/form/form_renderer.js9
-rw-r--r--addons/web/static/src/js/views/pivot/pivot_model.js18
-rw-r--r--addons/web/static/tests/views/pivot_tests.js38
4 files changed, 46 insertions, 21 deletions
diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js
index 72e65f985a8..5126138bc36 100644
--- a/addons/web/static/lib/qweb/qweb2.js
+++ b/addons/web/static/lib/qweb/qweb2.js
@@ -173,7 +173,7 @@ var QWeb2 = {
new_dict[as_first] = index === 0;
new_dict[as_last] = index + 1 === size;
new_dict[as_parity] = (index % 2 == 1 ? 'odd' : 'even');
- if (cur.constructor === Object) {
+ if (cur && cur.constructor === Object) {
this.extend(new_dict, cur);
}
new_dict[as] = cur;
diff --git a/addons/web/static/src/js/views/form/form_renderer.js b/addons/web/static/src/js/views/form/form_renderer.js
index ca26d7e90ad..a10e75f1944 100644
--- a/addons/web/static/src/js/views/form/form_renderer.js
+++ b/addons/web/static/src/js/views/form/form_renderer.js
@@ -370,7 +370,7 @@ var FormRenderer = BasicRenderer.extend({
var visible_buttons = buttons_partition[1];
// Get the unfolded buttons according to window size
- var nb_buttons = [2, 2, 4, 6][config.device.size_class] || 7;
+ var nb_buttons = this._renderButtonBoxNbButtons();
var unfolded_buttons = visible_buttons.slice(0, nb_buttons).concat(invisible_buttons);
// Get the folded buttons
@@ -411,6 +411,13 @@ var FormRenderer = BasicRenderer.extend({
return $result;
},
/**
+ * @private
+ * @returns {integer}
+ */
+ _renderButtonBoxNbButtons: function () {
+ return [2, 2, 4, 6][config.device.size_class] || 7;
+ },
+ /**
* @private
* @param {Object} node
* @returns {jQueryElement}
diff --git a/addons/web/static/src/js/views/pivot/pivot_model.js b/addons/web/static/src/js/views/pivot/pivot_model.js
index 88d0aee83b8..5758b906421 100644
--- a/addons/web/static/src/js/views/pivot/pivot_model.js
+++ b/addons/web/static/src/js/views/pivot/pivot_model.js
@@ -440,12 +440,10 @@ var PivotModel = AbstractModel.extend({
// if we don't have the key 'groupBy' in params. In that case,
// we want to have the full open state for the groupbys.
self._updateTree(old_row.root, self.data.main_row.root);
- self._updateMainGroupBys(old_row, self.data.main_row);
}
if (!('pivot_column_groupby' in (params.context || {}))) {
self._updateTree(old_col.root, self.data.main_col.root);
- self._updateMainGroupBys(old_col, self.data.main_col);
}
});
},
@@ -986,7 +984,8 @@ var PivotModel = AbstractModel.extend({
});
var index = 0;
- var rowGroupBys = !_.isEmpty(this.data.groupedBy) ? this.data.groupedBy : this.initialRowGroupBys;
+ var rowGroupBys = !_.isEmpty(this.data.groupedBy) ? this.data.groupedBy : this.initialRowGroupBys.slice();
+ this.data.groupedBy = rowGroupBys;
var colGroupBys = this.data.colGroupBys;
var dataPoint, row, col, attrs, cell_value;
var main_row_header, main_col_header;
@@ -1119,19 +1118,6 @@ var PivotModel = AbstractModel.extend({
}
},
/**
- * Updates the groupBys that the main[row | col] holds
- *
- * @private
- * @param {Object} old: The main abstract header before reload
- * @param {Object} main: The main abstract header after reload
- *
- */
- _updateMainGroupBys: function (old, main) {
- var new_groupby_length = this._getHeaderDepth(main.root) - 1;
- var new_groupby_list = old.root.groupbys.slice(0, new_groupby_length);
- main.root.groupbys = new_groupby_list;
- },
- /**
* @param {Object} old_tree
* @param {Object} new_tree
*/
diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js
index ccbf24895dd..5dbc03e1a2b 100644
--- a/addons/web/static/tests/views/pivot_tests.js
+++ b/addons/web/static/tests/views/pivot_tests.js
@@ -1096,7 +1096,7 @@ QUnit.module('Views', {
pivot.destroy();
});
- QUnit.skip('Reload, group by columns, reload', function (assert) {
+ QUnit.test('Reload, group by columns, reload', function (assert) {
assert.expect(2);
var pivot = createView({
@@ -1118,7 +1118,7 @@ QUnit.module('Views', {
pivot_row_groupby: []};
// Check that column groupbys were not lost
- assert.deepEqual(pivot.getContext(), expectedContext,
+ assert.deepEqual(pivot.getOwnedQueryParams(), {context: expectedContext},
'Column groupby not lost after first reload');
// Set a column groupby
@@ -1132,12 +1132,44 @@ QUnit.module('Views', {
pivot_measures: ['__count'],
pivot_row_groupby: []};
- assert.deepEqual(pivot.getContext(), expectedContext,
+ assert.deepEqual(pivot.getOwnedQueryParams(), {context: expectedContext},
'Column groupby not lost after second reload');
pivot.destroy();
});
+ QUnit.test('Empty results keep groupbys', function (assert) {
+ assert.expect(2);
+
+ var pivot = createView({
+ View: PivotView,
+ model: "partner",
+ data: this.data,
+ arch: '<pivot/>',
+ });
+
+ // Set a column groupby
+ pivot.$('thead .o_pivot_header_cell_closed').click();
+ pivot.$('.o_field_selection .dropdown-item[data-field=customer]').click();
+
+ // Set a domain for empty results
+ pivot.update({domain: [['id', '=', false]]});
+
+ var expectedContext = {pivot_column_groupby: ['customer'],
+ pivot_measures: ['__count'],
+ pivot_row_groupby: []};
+ assert.deepEqual(pivot.getOwnedQueryParams(), {context: expectedContext},
+ 'Column groupby not lost after empty results');
+
+ // Set a domain for not empty results
+ pivot.update({domain: [['product_id', '=', 37]]});
+
+ assert.deepEqual(pivot.getOwnedQueryParams(), {context: expectedContext},
+ 'Column groupby not lost after reload after empty results');
+
+ pivot.destroy();
+ });
+
QUnit.test('correctly uses pivot_ keys from the context', function (assert) {
assert.expect(7);