[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
This commit is contained in:
Martin Trigaux
2022-03-29 10:56:16 +02:00
parent a9db04a719
commit 1d8f6a5bcd
@@ -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 = {