Files
odoo_source/addons/spreadsheet_dashboard/tests/test_spreadsheet_dashboard.py
T
Lucas Lefèvre (lul) aa118d7dc0 [IMP] spreadsheet_dashboard_edition: load dashboard with user locale
Currently, spreadsheet dashboards always display numbers with the en_US
format, no matter the user's lang.

That's because the locale is hardcoded in the spreadsheet source file, in
the source code (or it falls back to the default en_US locale if it's missing).

With this commit, we dynamically change the spreadsheet locale with the user's
locale when he loads a dashboard.

We can change the locale with every user because the dashboard is readonly.
It cannot create a giant mess with dates in various locales.

Limitation
----------
Since hardcoded date formats are not changed when the locale changes, dates
will keep the en_US format. However, most (if not all) dates in dashboards
are coming from ODOO.PIVOT and ODOO.LIST functions, which compute the formats
dynamically based on the current locale.

closes odoo/odoo#135119

Task: 3484002
Related: odoo/enterprise#47284
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
2023-10-11 17:01:57 +00:00

52 lines
1.8 KiB
Python

import json
from odoo.exceptions import UserError
from .common import DashboardTestCommon
class TestSpreadsheetDashboard(DashboardTestCommon):
def test_create_with_default_values(self):
group = self.env["spreadsheet.dashboard.group"].create(
{"name": "a group"}
)
dashboard = self.env["spreadsheet.dashboard"].create(
{
"name": "a dashboard",
"dashboard_group_id": group.id,
}
)
self.assertEqual(dashboard.group_ids, self.env.ref("base.group_user"))
self.assertEqual(
json.loads(dashboard.spreadsheet_data),
dashboard._empty_spreadsheet_data()
)
def test_unlink_prevent_spreadsheet_group(self):
group = self.env["spreadsheet.dashboard.group"].create(
{"name": "a_group"}
)
self.env['ir.model.data'].create({
'name': group.name,
'module': 'spreadsheet_dashboard',
'model': group._name,
'res_id': group.id,
})
with self.assertRaises(UserError, msg="You cannot delete a_group as it is used in another module"):
group.unlink()
def test_load_with_user_locale(self):
dashboard = self.create_dashboard().with_user(self.user)
self.user.lang = "en_US"
data = dashboard.get_readonly_dashboard()
locale = data["snapshot"]["settings"]["locale"]
self.assertEqual(locale["code"], "en_US")
self.assertEqual(len(data["revisions"]), 0)
self.env.ref("base.lang_fr").active = True
self.user.lang = "fr_FR"
data = dashboard.get_readonly_dashboard()
locale = data["snapshot"]["settings"]["locale"]
self.assertEqual(locale["code"], "fr_FR")
self.assertEqual(len(data["revisions"]), 0)