oca-ocb-report/odoo-bringout-oca-ocb-spreadsheet_dashboard/spreadsheet_dashboard/controllers/dashboards_controllers.py
Ernad Husremovic 184bb0e321 19.0 vanilla
2026-03-09 09:32:02 +01:00

33 lines
1.3 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http
from odoo.http import request
class DashboardDataRoute(http.Controller):
@http.route(
['/spreadsheet/dashboard/data/<model("spreadsheet.dashboard"):dashboard>'],
type='http',
auth='user',
readonly=True
)
def get_dashboard_data(self, dashboard):
dashboard = dashboard.exists()
if not dashboard:
raise request.not_found()
cids_str = request.cookies.get('cids', str(request.env.user.company_id.id))
cids = [int(cid) for cid in cids_str.split('-')]
dashboard = dashboard.with_context(allowed_company_ids=cids)
if dashboard._dashboard_is_empty() and dashboard.sample_dashboard_file_path:
sample_data = dashboard._get_sample_dashboard()
if sample_data:
return request.make_json_response({
'snapshot': sample_data,
'is_sample': True,
})
body = dashboard._get_serialized_readonly_dashboard()
headers = [
('Content-Length', len(body)),
('Content-Type', 'application/json; charset=utf-8'),
]
return request.make_response(body, headers)