[FIX] board: display time range descriptions

In saas-13.3, time range descriptions of a reporting view in comparison
mode were not correctly saved when adding the view to the Dashboard app.
This is no more the case (the bug has been corrected with the
introduction of the comparison menu). The present commit simply
consists in the forwart port of two (adatpted) tests of the original
commit.

closes odoo/odoo#54010

X-original-commit: 9f246a7d8f45203f7b0a9111c0ffd381b5e09052
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Mathieu Duckerts-Antoine
2020-07-03 07:09:41 +00:00
parent f29f7c63ae
commit 25258e314e
@@ -12,6 +12,8 @@ const cpHelpers = testUtils.controlPanel;
var createActionManager = testUtils.createActionManager;
var createView = testUtils.createView;
const patchDate = testUtils.mock.patchDate;
QUnit.module('Dashboard', {
beforeEach: function () {
this.data = {
@@ -1039,4 +1041,113 @@ QUnit.test('click on a cell of pivot view inside dashboard', async function (ass
form.destroy();
});
QUnit.test('correctly save the time ranges of a reporting view in comparison mode', async function (assert) {
assert.expect(1);
const unpatchDate = patchDate(2020, 6, 1, 11, 0, 0);
this.data.partner.fields.date = { string: 'Date', type: 'date', sortable: true };
const actionManager = await createActionManager({
data: this.data,
archs: {
'partner,false,pivot': '<pivot><field name="foo"/></pivot>',
'partner,false,search': '<search><filter name="Date" date="date"/></search>',
},
mockRPC: function (route, args) {
if (route === '/board/add_to_dashboard') {
assert.deepEqual(args.context_to_save.comparison, {
comparisonId: "previous_period",
fieldName: "date",
fieldDescription: "Date",
rangeDescription: "July 2020",
range: ["&",["date", ">=", "2020-07-01"], ["date", "<=", "2020-07-31"]],
comparisonRange: ["&", ["date", ">=", "2020-06-01"], ["date", "<=", "2020-06-30"]],
comparisonRangeDescription: "June 2020",
});
return Promise.resolve(true);
}
return this._super.apply(this, arguments);
},
});
await actionManager.doAction({
id: 1,
res_model: 'partner',
type: 'ir.actions.act_window',
views: [[false, 'pivot']],
});
// filter on July 2020
await cpHelpers.toggleFilterMenu(actionManager);
await cpHelpers.toggleMenuItem(actionManager, 'Date');
await cpHelpers.toggleMenuItemOption(actionManager, 'Date', 'July');
// compare July 2020 to June 2020
await cpHelpers.toggleComparisonMenu(actionManager);
await cpHelpers.toggleMenuItem(actionManager, 0);
// add the view to the dashboard
await cpHelpers.toggleFavoriteMenu(actionManager);
await testUtils.dom.click($('.o_add_to_board > button'));
await testUtils.fields.editInput($('.o_add_to_board input'), 'a name');
await testUtils.dom.click($('.o_add_to_board div button'));
unpatchDate();
actionManager.destroy();
});
QUnit.test('correctly display the time range descriptions of a reporting view in comparison mode', async function (assert) {
assert.expect(1);
this.data.partner.fields.date = { string: 'Date', type: 'date', sortable: true };
this.data.partner.records[0].date = '2020-07-15';
const form = await createView({
View: BoardView,
model: 'board',
data: this.data,
arch: `<form string="My Dashboard">
<board style="2-1">
<column>
<action string="ABC" name="51"></action>
</column>
</board>
</form>`,
archs: {
'partner,1,pivot':
'<pivot string="Partner"></pivot>',
},
mockRPC: function (route, args) {
if (route === '/board/static/src/img/layout_1-1-1.png') {
return Promise.resolve();
}
if (route === '/web/action/load') {
return Promise.resolve({
context: JSON.stringify({ comparison: {
comparisonId: "previous_period",
fieldName: "date",
fieldDescription: "Date",
rangeDescription: "July 2020",
range: ["&",["date", ">=", "2020-07-01"], ["date", "<=", "2020-07-31"]],
comparisonRange: ["&", ["date", ">=", "2020-06-01"], ["date", "<=", "2020-06-30"]],
comparisonRangeDescription: "June 2020",
}}),
domain: '[]',
res_model: 'partner',
views: [[1, 'pivot']],
});
}
return this._super.apply(this, arguments);
},
});
assert.deepEqual(
[...form.el.querySelectorAll('div.o_pivot th.o_pivot_origin_row')].map(el => el.innerText),
['June 2020', 'July 2020', 'Variation']
);
form.destroy();
});
});