summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core
diff options
context:
space:
mode:
authorMathieu Duckerts-Antoine <dam@odoo.com>2020-05-25 18:11:02 +0000
committerMathieu Duckerts-Antoine <dam@odoo.com>2020-06-04 19:32:42 +0000
commitbe5a51a345b8986da0e19627260f64f984e11ae9 (patch)
tree4a0b1e5b0bfdad3124718ccf8e67164b5bbe07dd /addons/web/static/src/js/core
parent884ef9f7ee345ab1e940dbf88f4432b7e10f36e3 (diff)
[IMP] web: Comparison menu
This commit replaces the "time range menu" in the control panel by a new component: the "comparison menu". Its purpose is roughly the same: compare a period of data in a reporting view with the previous period or the previous year. Its implementation is a bit simpler: it will only appear if at least one date filter is selected in the search view, and will suggest to compare each selected date option with the previous period or the previous year. Task ID: 2245719 Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com> Co-authored-by: Julien Mougenot <jum@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/core')
-rw-r--r--addons/web/static/src/js/core/domain.js126
1 files changed, 0 insertions, 126 deletions
diff --git a/addons/web/static/src/js/core/domain.js b/addons/web/static/src/js/core/domain.js
index 07d785b9292..ad0cfba9ae4 100644
--- a/addons/web/static/src/js/core/domain.js
+++ b/addons/web/static/src/js/core/domain.js
@@ -244,132 +244,6 @@ var Domain = collections.Tree.extend({
.replace(/false/g, "False")
.replace(/true/g, "True");
},
- /*
- * @param {string} fieldName
- * @param {string} period
- * @param {string} type ('date' or 'datetime')
- * @param {string} comparisonPeriod
- * @returns {string} a domain in string form
- */
- constructDomain: function (fieldName, period, type, comparisonPeriod) {
- var leftBoundaryParams, rightBoundaryParams;
- var offsetPeriodParams;
- function makeInterval () {
- switch (comparisonPeriod) {
- case 'previous_period':
- _.each(offsetPeriodParams, function (value, key) {
- if (!leftBoundaryParams[key] ||_.isNumber(leftBoundaryParams[key])) {
- leftBoundaryParams[key] = value + (leftBoundaryParams[key] || 0);
- } else {
- leftBoundaryParams[key] = value + ' + ' + leftBoundaryParams[key];
- }
- if (!rightBoundaryParams[key] || _.isNumber(rightBoundaryParams[key])) {
- rightBoundaryParams[key] = value + (rightBoundaryParams[key] || 0);
- } else {
- rightBoundaryParams[key] = value + ' + ' + rightBoundaryParams[key];
- }
- });
- break;
- case 'previous_year':
- leftBoundaryParams.years = leftBoundaryParams.years ? leftBoundaryParams.years - 1 : -1;
- rightBoundaryParams.years = rightBoundaryParams.years ? rightBoundaryParams.years - 1 : -1;
- break;
- }
-
- var stringifyParams = function (value, key) {
- return key + '=' + value;
- };
- var leftBoundaryStringifyParams = _.map(leftBoundaryParams, stringifyParams).join(', ');
- var rightBoundaryStringifyParams = _.map(rightBoundaryParams, stringifyParams).join(', ');
-
- if (type === 'date') {
- return "['&'," +
- "('" + fieldName + "', '>=', (context_today() + relativedelta(" + leftBoundaryStringifyParams + ")).strftime('%Y-%m-%d'))," +
- "('" + fieldName + "', '<', (context_today() + relativedelta(" + rightBoundaryStringifyParams + ")).strftime('%Y-%m-%d'))"+
- "]";
- }
- else {
- return "['&'," +
- "('" + fieldName + "', '>=', " +
- "(datetime.datetime.combine(context_today() + relativedelta(" + leftBoundaryStringifyParams + "), datetime.time(0,0,0)).to_utc()).strftime('%Y-%m-%d %H:%M:%S'))," +
- "('" + fieldName + "', '<', " +
- "(datetime.datetime.combine(context_today() + relativedelta(" + rightBoundaryStringifyParams + "), datetime.time(0,0,0)).to_utc()).strftime('%Y-%m-%d %H:%M:%S'))"+
- "]";
- }
- }
- switch (period) {
- case 'today':
- leftBoundaryParams = {};
- rightBoundaryParams = {days: 1};
- offsetPeriodParams = {days: -1};
- return makeInterval();
- case 'this_week':
- leftBoundaryParams = {weeks: -1, days: 1, weekday: 0};
- rightBoundaryParams = {days: 1, weekday: 0};
- offsetPeriodParams = {weeks: -1};
- return makeInterval();
- case 'this_month':
- leftBoundaryParams = {day: 1};
- rightBoundaryParams = {day: 1, months: 1};
- offsetPeriodParams = {months: -1};
- return makeInterval();
- case 'this_quarter':
- leftBoundaryParams = {months: '- (context_today().month - 1) % 3', day: 1};
- rightBoundaryParams = {months: '3 - (context_today().month - 1) % 3', day: 1};
- offsetPeriodParams = {months: -3};
- return makeInterval();
- case 'this_year':
- leftBoundaryParams = {month: 1, day: 1};
- rightBoundaryParams = {month: 1, day: 1, years: 1};
- offsetPeriodParams = {years: -1};
- return makeInterval();
- case 'yesterday':
- leftBoundaryParams = {days: -1};
- rightBoundaryParams = {};
- offsetPeriodParams = {days: -1};
- return makeInterval();
- case 'last_week':
- leftBoundaryParams = {weeks: -2, days: 1, weekday: 0};
- rightBoundaryParams = {weeks: -1, days: 1, weekday: 0};
- offsetPeriodParams = {weeks: -1};
- return makeInterval();
- case 'last_month':
- leftBoundaryParams = {months: -1, day: 1};
- rightBoundaryParams = {day: 1};
- offsetPeriodParams = {months: -1};
- return makeInterval();
- case 'last_quarter':
- leftBoundaryParams = {months: '- 3 - (context_today().month - 1) % 3', day: 1};
- rightBoundaryParams = {months: '- (context_today().month - 1) % 3', day: 1};
- offsetPeriodParams = {months: -3};
- return makeInterval();
- case 'last_year':
- leftBoundaryParams = {month: 1, day: 1, years: -1};
- rightBoundaryParams = {month: 1, day: 1};
- offsetPeriodParams = {years: -1};
- return makeInterval();
- case 'last_7_days':
- leftBoundaryParams = {days: -7};
- rightBoundaryParams = {};
- offsetPeriodParams = {days: -7};
- return makeInterval();
- case 'last_30_days':
- leftBoundaryParams = {days: -30};
- rightBoundaryParams = {};
- offsetPeriodParams = {days: -30};
- return makeInterval();
- case 'last_365_days':
- leftBoundaryParams = {days: -365};
- rightBoundaryParams = {};
- offsetPeriodParams = {days: -365};
- return makeInterval();
- case 'last_5_years':
- leftBoundaryParams = {years: -5};
- rightBoundaryParams = {};
- offsetPeriodParams = {years: -5};
- return makeInterval();
- }
- },
/**
* Converts a string representation of the Python prefix-array
* representation of a domain to a JS prefix-array representation of this