mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
report_generate_helper: change method name, clean code, update doc
This commit is contained in:
@@ -1 +1,2 @@
|
||||
from . import report_helper
|
||||
from . import base
|
||||
from . import ir_actions_report
|
||||
|
||||
@@ -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:
|
||||
13
report_generate_helper/models/ir_actions_report.py
Normal file
13
report_generate_helper/models/ir_actions_report.py
Normal 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('-', '_')}"
|
||||
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user