[FIX] website{,_sale_link_tracker}: ecommerce graph today

The UTM graph data in Website > Dasboard > Analytics is not getting
properly filtered on the basis of values of date_from and date_to on
website_sale dashboard.

The field confirmation date which is of type datetime while date_from
and date_to are of date string in local browser timezone.

Hence date_domain is not perfect as shown below on local date 29th april
2019, we would send:

('confirmation_date', '>=', '2019-04-22'),
('confirmation_date', '<=', '2019-04-29')

But in reality we could want a from midnight of week before the current
UTC day, and to current UTC now or 23:59:59 of current UTC day.

This way, the data sent back matches more what is expected, instead of
the preceding domain, we would then have the following:

- if UTC now corresponding to local now is on '2019-04-29'

 ('confirmation_date', '>=', '2019-04-22 00:00:00'),
 ('confirmation_date', '<=', '2019-04-29 23:59:59')

- if UTC now corresponding to local now is on '2019-04-28':

 ('confirmation_date', '>=', '2019-04-21 00:00:00'),
 ('confirmation_date', '<=', '2019-04-28 23:59:59')

- if UTC now corresponding to local now is on '2019-04-30':

 ('confirmation_date', '>=', '2019-04-23 00:00:00'),
 ('confirmation_date', '<=', '2019-04-30 23:59:59')

And each one will be displayed as days 22 up to 29 in line chart (with
local today 29 being the last day of the chart and contening orders of
the current UTC day).

With these change in the UTM pie chart:

- a local date that is before a UTC date => we see the sales from up to
  today UTC instead of from up to before yesterday UTC

- a local date that is the same as an UTC date => we see the sale from
  up to today UTC instead of yesterday UTC

And in the line chart (that already had half of the fix in f6fc7c2319):

- a local date that is before a UTC date => we see the sales from up to
  today UTC instead of from up to yesterday UTC

- a local date that is after a UTC date => we see the sales of current
  UTC day + range of days (eg. for a week 7) instead of current UTC day +
  range of days minus 1 (eg. for a week 6).

opw-1971539
closes #33041

Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>


Co-authored-by: Nicolas Lempereur <nle-odoo@users.noreply.github.com>
This commit is contained in:
Meghna Jaswani
2019-05-03 11:29:34 +00:00
committed by Nicolas Lempereur
co-authored by Nicolas Lempereur
parent 97b44806f5
commit 8df4bbf1ed
2 changed files with 11 additions and 6 deletions
@@ -33,8 +33,8 @@ var Dashboard = AbstractAction.extend(ControlPanelMixin, {
this._super(parent, context);
this.date_range = 'week'; // possible values : 'week', 'month', year'
this.date_from = moment().subtract(1, 'week');
this.date_to = moment();
this.date_from = moment.utc().subtract(1, 'week');
this.date_to = moment.utc();
this.dashboards_templates = ['website.dashboard_header', 'website.dashboard_content'];
this.graphs = [];
@@ -230,13 +230,13 @@ var Dashboard = AbstractAction.extend(ControlPanelMixin, {
on_date_range_button: function(date_range) {
if (date_range === 'week') {
this.date_range = 'week';
this.date_from = moment().subtract(1, 'weeks');
this.date_from = moment.utc().subtract(1, 'weeks');
} else if (date_range === 'month') {
this.date_range = 'month';
this.date_from = moment().subtract(1, 'months');
this.date_from = moment.utc().subtract(1, 'months');
} else if (date_range === 'year') {
this.date_range = 'year';
this.date_from = moment().subtract(1, 'years');
this.date_from = moment.utc().subtract(1, 'years');
} else {
console.log('Unknown date range. Choose between [week, month, year]');
return;
@@ -1,8 +1,11 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import datetime, time
from odoo import http
from odoo.addons.website_sale.controllers.backend import WebsiteSaleBackend
from odoo.fields import Date
from odoo.http import request
@@ -10,8 +13,10 @@ class WebsiteSaleLinkTrackerBackend(WebsiteSaleBackend):
@http.route()
def fetch_dashboard_data(self, website_id, date_from, date_to):
datetime_from = datetime.combine(Date.from_string(date_from), time.min)
datetime_to = datetime.combine(Date.from_string(date_to), time.max)
results = super(WebsiteSaleLinkTrackerBackend, self).fetch_dashboard_data(website_id, date_from, date_to)
results['dashboards']['sales']['utm_graph'] = self.fetch_utm_data(date_from, date_to)
results['dashboards']['sales']['utm_graph'] = self.fetch_utm_data(datetime_from, datetime_to)
return results
def fetch_utm_data(self, date_from, date_to):