summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/sample_server.js
diff options
context:
space:
mode:
authorMathieu Duckerts-Antoine <dam@odoo.com>2020-08-11 08:32:43 +0000
committerMathieu Duckerts-Antoine <dam@odoo.com>2020-08-12 08:52:20 +0000
commitfd6182443f68af3b6418195b13a4ab6c40599572 (patch)
treefd1a408104eb318ab6f139f0a47b937e0f2c5ad9 /addons/web/static/src/js/views/sample_server.js
parent06b8af3212e2debb7e364e0b429ec6c2db5214e8 (diff)
[IMP] web: sample data in reporting views (preparatory work)
The present commit brings the global changes necessary to have sample data in the reporting views. This includes several modifications/ fixes of the sample server (many of them for better visual results). Task ID: 2282196 Co-authored-by: Aaron Bohy <aab@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/views/sample_server.js')
-rw-r--r--addons/web/static/src/js/views/sample_server.js29
1 files changed, 20 insertions, 9 deletions
diff --git a/addons/web/static/src/js/views/sample_server.js b/addons/web/static/src/js/views/sample_server.js
index d716a565b32..c56ced9cead 100644
--- a/addons/web/static/src/js/views/sample_server.js
+++ b/addons/web/static/src/js/views/sample_server.js
@@ -145,7 +145,7 @@ odoo.define('web.SampleServer', function (require) {
_aggregateFields(measures, records) {
const values = {};
for (const { fieldName, type } of measures) {
- if (type === 'float' || type === 'integer') {
+ if (['float', 'integer', 'monetary'].includes(type)) {
if (records.length) {
let value = 0;
for (const record of records) {
@@ -333,7 +333,6 @@ odoo.define('web.SampleServer', function (require) {
_getRandomSubRecordId() {
return Math.floor(Math.random() * SampleServer.SUB_RECORDSET_SIZE) + 1;
}
-
/**
* Mocks calls to the read method.
* @private
@@ -397,9 +396,10 @@ odoo.define('web.SampleServer', function (require) {
}
for (const groupBySpec of groupBy) {
let [fieldName, interval] = groupBySpec.split(':');
+ interval = interval || 'month';
const { type, relation } = fields[fieldName];
if (type) {
- const gb = { fieldName, type, interval, relation };
+ const gb = { fieldName, type, interval, relation, alias: groupBySpec };
normalizedGroupBys.push(gb);
}
}
@@ -422,12 +422,12 @@ odoo.define('web.SampleServer', function (require) {
const [fieldName, aggregateFunction] = measureSpec.split(':');
const { type } = fields[fieldName];
if (!params.groupBy.includes(fieldName) && type &&
- (type !== 'many2one' || aggregateFunction !== 'count_distinct')) {
+ (type !== 'many2one' || aggregateFunction !== 'count_distinct')) {
measures.push({ fieldName, type });
}
}
- const result = [];
+ let result = [];
for (const id in groups) {
const records = groups[id];
const group = { __domain: [] };
@@ -438,12 +438,22 @@ odoo.define('web.SampleServer', function (require) {
group[countKey] = records.length;
const firstElem = records[0];
for (const gb of normalizedGroupBys) {
- const { fieldName } = gb;
- group[fieldName] = this._formatValue(firstElem[fieldName], gb);
+ const { alias, fieldName } = gb;
+ group[alias] = this._formatValue(firstElem[fieldName], gb);
}
Object.assign(group, this._aggregateFields(measures, records));
result.push(group);
}
+ if (normalizedGroupBys.length > 0) {
+ const { alias, interval, type } = normalizedGroupBys[0];
+ result = utils.sortBy(result, (group) => {
+ const val = group[alias];
+ if (['date', 'datetime'].includes(type)) {
+ return moment(val, SampleServer.FORMATS[interval]);
+ }
+ return val;
+ });
+ }
return result;
}
@@ -627,11 +637,12 @@ odoo.define('web.SampleServer', function (require) {
SampleServer.FORMATS = {
day: 'YYYY-MM-DD',
- week: 'ww YYYY',
+ week: '[W]ww YYYY',
month: 'MMMM YYYY',
quarter: '[Q]Q YYYY',
year: 'Y',
};
+ SampleServer.DISPLAY_FORMATS = Object.assign({}, SampleServer.FORMATS, { day: 'DD MMM YYYY' });
SampleServer.MAIN_RECORDSET_SIZE = 16;
SampleServer.SUB_RECORDSET_SIZE = 5;
@@ -641,7 +652,7 @@ odoo.define('web.SampleServer', function (require) {
SampleServer.MAX_INTEGER = 50;
SampleServer.MAX_COLOR_INT = 7;
SampleServer.MAX_MONETARY = 100000;
- SampleServer.DATE_DELTA = 24 * 7; // in hours -> 7 days
+ SampleServer.DATE_DELTA = 24 * 60; // in hours -> 60 days
SampleServer.SAMPLE_COUNTRIES = ["Belgium", "France", "Portugal", "Singapore", "Australia"];
SampleServer.SAMPLE_PEOPLE = [