mirror of
https://github.com/bringout/oca-ocb-report.git
synced 2026-04-21 19:42:09 +02:00
19.0 vanilla
This commit is contained in:
parent
62d197ac8b
commit
184bb0e321
667 changed files with 691406 additions and 239886 deletions
|
|
@ -0,0 +1,2 @@
|
|||
from . import share
|
||||
from . import dashboards_controllers
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
# 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)
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
from odoo import http, _
|
||||
from odoo.http import request
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
class DashboardShareRoute(http.Controller):
|
||||
@http.route(['/dashboard/share/<int:share_id>/<token>'], type='http', auth='public')
|
||||
def share_portal(self, share_id=None, token=None):
|
||||
share = request.env["spreadsheet.dashboard.share"].sudo().browse(share_id).exists()
|
||||
if not share:
|
||||
raise request.not_found()
|
||||
share._check_dashboard_access(token)
|
||||
download_url = ""
|
||||
if request.env.user.has_group('base.group_allow_export'):
|
||||
download_url = f"/dashboard/download/{share.id}/{token}"
|
||||
return request.render(
|
||||
"spreadsheet.public_spreadsheet_layout",
|
||||
{
|
||||
"spreadsheet_name": share.dashboard_id.name,
|
||||
"share": share,
|
||||
"is_frozen": True,
|
||||
"session_info": request.env["ir.http"].session_info(),
|
||||
"props": {
|
||||
"dataUrl": f"/dashboard/data/{share.id}/{token}",
|
||||
"downloadExcelUrl": download_url,
|
||||
"mode": "dashboard",
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
@http.route(["/dashboard/download/<int:share_id>/<token>"],
|
||||
type='http', auth='user', readonly=True)
|
||||
def download(self, token=None, share_id=None):
|
||||
share = request.env["spreadsheet.dashboard.share"].sudo().browse(share_id)
|
||||
share._check_dashboard_access(token)
|
||||
if not request.env.user.has_group('base.group_allow_export'):
|
||||
raise UserError(_("You don't have the rights to export data. Please contact an Administrator."))
|
||||
stream = request.env["ir.binary"]._get_stream_from(
|
||||
share, "excel_export", filename=share.name
|
||||
)
|
||||
return stream.get_response()
|
||||
|
||||
@http.route(
|
||||
["/dashboard/data/<int:share_id>/<token>"],
|
||||
type="http",
|
||||
auth="public",
|
||||
methods=["GET"],
|
||||
readonly=True,
|
||||
)
|
||||
def get_shared_dashboard_data(self, share_id, token):
|
||||
share = (
|
||||
request.env["spreadsheet.dashboard.share"]
|
||||
.sudo()
|
||||
.browse(share_id)
|
||||
.exists()
|
||||
)
|
||||
if not share:
|
||||
raise request.not_found()
|
||||
|
||||
share._check_dashboard_access(token)
|
||||
stream = request.env["ir.binary"]._get_stream_from(
|
||||
share, "spreadsheet_binary_data"
|
||||
)
|
||||
return stream.get_response()
|
||||
Loading…
Add table
Add a link
Reference in a new issue