From 1d8f6a5bcd2b565c474d040f98ce422c6e00d477 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 4 Mar 2022 15:33:45 +0000 Subject: [PATCH] [REF] base: new report methods api.model That use report references and no recordset. This avoids mixing environment of rendering and access to the report object. Part-of: odoo/odoo#85110 --- odoo/addons/base/models/ir_actions_report.py | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/odoo/addons/base/models/ir_actions_report.py b/odoo/addons/base/models/ir_actions_report.py index bd2d0c9abfe..ad24eac3463 100644 --- a/odoo/addons/base/models/ir_actions_report.py +++ b/odoo/addons/base/models/ir_actions_report.py @@ -528,6 +528,27 @@ class IrActionsReport(models.Model): context = self.env['res.users'].context_get() return report_obj.with_context(context).sudo().search(conditions, limit=1) + @api.model + def _get_report(self, report_ref): + """Get the report (with sudo) from an id or xmlid + report_ref: can be one of + - ir.actions.report id + - ir.actions.report report_name + - ir.model.data reference + """ + ReportSudo = self.env['ir.actions.report'].sudo() + if isinstance(report_ref, int): + return ReportSudo.browse(report_ref) + report = ReportSudo.search([('report_name', '=', report_ref)], limit=1) + if report: + return report + report = self.env.ref(report_ref) + if report: + if report._name != "ir.actions.report": + raise ValueError("Fetching report %r: type %s, expected ir.actions.report" % (report_ref, report._name)) + return report.sudo() + raise ValueError("Fetching report %r: report not found" % report_ref) + @api.model def barcode(self, barcode_type, value, **kwargs): defaults = {