Files
odoo_source/addons/spreadsheet_dashboard/models/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

27 lines
853 B
Python

import json
from odoo import fields, models
class SpreadsheetDashboard(models.Model):
_name = 'spreadsheet.dashboard'
_description = 'Spreadsheet Dashboard'
_inherit = "spreadsheet.mixin"
_order = 'sequence'
name = fields.Char(required=True, translate=True)
dashboard_group_id = fields.Many2one('spreadsheet.dashboard.group', required=True)
sequence = fields.Integer()
group_ids = fields.Many2many('res.groups', default=lambda self: self.env.ref('base.group_user'))
def get_readonly_dashboard(self):
self.ensure_one()
snapshot = json.loads(self.spreadsheet_data)
user_locale = self.env['res.lang']._get_user_spreadsheet_locale()
snapshot.setdefault('settings', {})['locale'] = user_locale
return {
'snapshot': snapshot,
'revisions': [],
}