diff options
| author | Jigar Patel <jat@openerp.com> | 2017-09-04 12:12:11 +0530 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2018-05-29 15:22:22 +0200 |
| commit | ecbafe92d22a2615f4ffa0a397a41548c0d59be4 (patch) | |
| tree | 96836a1c2ddc7f5433ef5a5e5734cac6257fffb1 /addons/web/static/tests | |
| parent | 4e5f826ce53b9e4cb73eea77935ea82e81ac66b9 (diff) | |
[IMP] web: _mockReadGroup method support week and year
Before this commit _mockReadGroup method support only day and month aggregate
function and return invalid domain for date type field.
With this commit _mockReadGroup method support week and year aggregate function.
And return correct domain having start date and end date if date type field.
Diffstat (limited to 'addons/web/static/tests')
| -rw-r--r-- | addons/web/static/tests/helpers/mock_server.js | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/addons/web/static/tests/helpers/mock_server.js b/addons/web/static/tests/helpers/mock_server.js index 148b7452678..b57b59eb2a7 100644 --- a/addons/web/static/tests/helpers/mock_server.js +++ b/addons/web/static/tests/helpers/mock_server.js @@ -737,6 +737,10 @@ var MockServer = Class.extend({ return false; } else if (aggregateFunction === 'day') { return moment(val).format('YYYY-MM-DD'); + } else if (aggregateFunction === 'week') { + return moment(val).format('ww YYYY'); + } else if (aggregateFunction === 'year') { + return moment(val).format('Y'); } else { return moment(val).format('MMMM YYYY'); } @@ -750,12 +754,7 @@ var MockServer = Class.extend({ value = (value ? value + ',' : value) + groupByField + '#'; var fieldName = groupByField.split(':')[0]; if (fields[fieldName].type === 'date') { - var aggregateFunction = groupByField.split(':')[1] || 'month'; - if (aggregateFunction === 'day') { - value += moment(record[fieldName]).format('YYYY-MM-DD'); - } else { - value += moment(record[fieldName]).format('MMMM YYYY'); - } + value += formatValue(groupByField, record[fieldName]); } else { value += record[groupByField]; } @@ -790,7 +789,28 @@ var MockServer = Class.extend({ } else { res[groupByField] = val; } - res.__domain = [[fieldName, "=", val]].concat(res.__domain); + + if (field.type === 'date') { + var aggregateFunction = groupByField.split(':')[1]; + var startDate, endDate; + if (aggregateFunction === 'day') { + startDate = moment(val, 'YYYY-MM-DD'); + endDate = startDate.clone().add(1, 'days'); + } else if (aggregateFunction === 'week') { + startDate = moment(val, 'ww YYYY'); + endDate = startDate.clone().add(1, 'weeks'); + } else if (aggregateFunction === 'year') { + startDate = moment(val, 'Y'); + endDate = startDate.clone().add(1, 'years'); + } else { + startDate = moment(val, 'MMMM YYYY'); + endDate = startDate.clone().add(1, 'months'); + } + res.__domain = [[fieldName, '>=', startDate.format('YYYY-MM-DD')], [fieldName, '<', endDate.format('YYYY-MM-DD')]].concat(res.__domain); + } else { + res.__domain = [[fieldName, '=', val]].concat(res.__domain); + } + }); // compute count key to match dumb server logic... |
