Files
dn20/accountant_cn/controllers/dn_report_controller.py
2026-11-17 17:57:08 +08:00

38 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
"""JSON endpoint feeding the report client action.
Odoo 20 renamed the JSON-RPC route type from ``json`` to ``jsonrpc``; such a
route receives the ``params`` object of the JSON-RPC envelope as keyword
arguments and its return value is wrapped back into ``{"result": ...}``. The
web client's ``rpc()`` helper does exactly that, so the payload returned here
is what the Owl component sees as the resolved value.
"""
import logging
from odoo import http
from odoo.http import request, route
_logger = logging.getLogger(__name__)
class DnReportController(http.Controller):
@route("/dn/report/data", type="jsonrpc", auth="user")
def get_report_data(self, report_id=None, options=None, **kwargs):
try:
report = request.env["dn.report"].browse(int(report_id or 0)).exists()
except (TypeError, ValueError):
report = request.env["dn.report"]
if not report:
return {"ok": False, "error": "Report not found."}
options = dict(options or {})
options.setdefault("company_ids", request.env.company.ids)
try:
data = report.get_report_data(options)
except Exception as exc: # noqa: BLE001 - surface the message in the UI
_logger.exception("DN report %s failed", report.code)
return {"ok": False, "error": str(exc)}
return {"ok": True, "data": data}