report_generate_helper: change method name, clean code, update doc

This commit is contained in:
Sébastien BEAU
2024-06-03 19:03:49 +02:00
parent 706c618c58
commit 0db02d4be7
4 changed files with 23 additions and 6 deletions

View File

@@ -1 +1,2 @@
from . import report_helper
from . import base
from . import ir_actions_report

View File

@@ -9,14 +9,17 @@ from odoo.tools.safe_eval import safe_eval, time
class Base(models.AbstractModel):
_inherit = "base"
def _get_report_converter(self):
return f"_render_{self.report_type.replace('-', '_')}"
def _generate_report(self, report_name):
"""
Generate the report matching the report_name for the self object
def get_report(self, report_name):
The method will return a tuple with the name of the field and the content
return (filename, content)
"""
report = self.env["ir.actions.report"]._get_report(report_name)
method_name = report._get_report_converter()
method = getattr(self.env["ir.actions.report"].sudo(), method_name)
method = getattr(self.env["ir.actions.report"], method_name)
content, extension = method(report_name, self.ids)
if report.print_report_name and len(self) == 1:

View File

@@ -0,0 +1,13 @@
# Copyright 2024 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
class IrActionsActions(models.Model):
_inherit = "ir.actions.report"
def _get_report_converter(self):
return f"_render_{self.report_type.replace('-', '_')}"

View File

@@ -4,4 +4,4 @@ from odoo.tests import common
class TestReportLabel(common.TransactionCase):
def test_get_report(self):
module = self.env["ir.module.module"].search([])[1]
self.assertTrue(module.get_report("base.report_irmodulereference"))
self.assertTrue(module._generate_report("base.report_irmodulereference"))