[FIX] website_links: support foreign language for links graphs

When a user creates a link that is tracked, an interface with graphs is
presented to him so that he can track the performance of his tracked
link. Unfortunately, these graphs did not work when the site was in a
foreign language. This was due to the fact that the code had not been
designed to handle this. This commit fixes the code so that it works in
all languages.

Note that the data is received via RPC and the python code format the
dates for the current language of the website. So we had to do a little
hack to make it work properly.

Steps to reproduce the issue:
- Install website_links module
- Go to the website app
- Click on Promote > Link Tracker
- Create a tracked link
- Visit the link
- Install Arabic (Syria) for your website
- Check the stats of your link in Arabic

=> There is a traceback and the data is not displayed.

task-3289167

closes odoo/odoo#126273

X-original-commit: e690da6ed1493e1def47cca6ef61e01ca8fa885f
Signed-off-by: Outagant Mehdi (mou) <mou@odoo.com>
This commit is contained in:
Guillaume (gdi)
2023-06-26 13:20:49 +02:00
parent b008b16122
commit 8eb8e08258
@@ -18,7 +18,7 @@ var BarChart = publicWidget.Widget.extend({
*/
init: function (parent, beginDate, endDate, dates) {
this._super.apply(this, arguments);
this.beginDate = beginDate;
this.beginDate = beginDate.locale("en");
this.endDate = endDate;
this.number_of_days = this.endDate.diff(this.beginDate, 'days') + 2;
this.dates = dates;
@@ -160,11 +160,18 @@ publicWidget.registry.websiteLinksCharts = publicWidget.Widget.extend({
var formattedClicksByDay = {};
var beginDate;
for (var i = 0; i < _clicksByDay.length; i++) {
var date = moment(_clicksByDay[i]['create_date:day'], 'DD MMMM YYYY');
// This is a trick to get the date without the local formatting.
// We can't simply do .locale("en") because some Odoo languages
// are not supported by moment.js (eg: Arabic Syria).
const date = moment(
_clicksByDay[i]["__domain"].find((el) => el.length && el.includes(">="))[2]
.split(" ")[0], "YYYY MM DD"
);
if (i === 0) {
beginDate = date;
}
formattedClicksByDay[date.format('YYYY-MM-DD')] = _clicksByDay[i]['create_date_count'];
formattedClicksByDay[date.locale("en").format("YYYY-MM-DD")] =
_clicksByDay[i]["create_date_count"];
}
// Process all time line chart data
@@ -239,11 +246,14 @@ publicWidget.registry.websiteLinksCharts = publicWidget.Widget.extend({
* @private
*/
_lastWeekClicksByCountry: function () {
var interval = moment().subtract(7, 'days').format('YYYY-MM-DD');
// 7 days * 24 hours * 60 minutes * 60 seconds * 1000 milliseconds.
const aWeekAgoDate = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
// get the date in the format YYYY-MM-DD.
const aWeekAgoString = aWeekAgoDate.toISOString().split("T")[0];
return this._rpc({
model: 'link.tracker.click',
method: 'read_group',
args: [[this.links_domain, ['create_date', '>', interval]], ['country_id']],
args: [[this.links_domain, ["create_date", ">", aWeekAgoString]], ["country_id"]],
kwargs: {groupby: 'country_id'},
});
},
@@ -251,11 +261,14 @@ publicWidget.registry.websiteLinksCharts = publicWidget.Widget.extend({
* @private
*/
_lastMonthClicksByCountry: function () {
var interval = moment().subtract(30, 'days').format('YYYY-MM-DD');
// 30 days * 24 hours * 60 minutes * 60 seconds * 1000 milliseconds.
const aMonthAgoDate = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
// get the date in the format YYYY-MM-DD.
const aMonthAgoString = aMonthAgoDate.toISOString().split("T")[0];
return this._rpc({
model: 'link.tracker.click',
method: 'read_group',
args: [[this.links_domain, ['create_date', '>', interval]], ['country_id']],
args: [[this.links_domain, ["create_date", ">", aMonthAgoString]], ["country_id"]],
kwargs: {groupby: 'country_id'},
});
},