diff --git a/README.md b/README.md
index b9b5683e9c..be93391e54 100644
--- a/README.md
+++ b/README.md
@@ -48,7 +48,7 @@ addon | version | maintainers | summary
[report_qweb_pdf_cover](report_qweb_pdf_cover/) | 16.0.1.0.0 | | Add front and back covers to your QWeb PDF reports
[report_qweb_pdf_watermark](report_qweb_pdf_watermark/) | 16.0.1.0.1 | | Add watermarks to your QWEB PDF reports
[report_qweb_signer](report_qweb_signer/) | 16.0.1.0.5 | | Sign Qweb PDFs usign a PKCS#12 certificate
-[report_substitute](report_substitute/) | 16.0.1.1.1 |
| This module allows to create substitution rules for report actions.
+[report_substitute](report_substitute/) | 16.0.1.1.2 |
| This module allows to create substitution rules for report actions.
[report_text_format_option](report_text_format_option/) | 16.0.1.0.0 | | Report Text Format Option
[report_wkhtmltopdf_param](report_wkhtmltopdf_param/) | 16.0.1.0.0 | | Add new parameters for a paper format to be used by wkhtmltopdf command as arguments.
[report_xlsx](report_xlsx/) | 16.0.2.0.2 | | Base module to create xlsx report
diff --git a/report_substitute/README.rst b/report_substitute/README.rst
index 35082aae4b..4b695d74ed 100644
--- a/report_substitute/README.rst
+++ b/report_substitute/README.rst
@@ -11,7 +11,7 @@ Report Substitute
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !! source digest: sha256:6e713ec7c433154ddfbdc2a954a61a5df2fcdabf03d875d3b3dd5bd0ce4ff980
+ !! source digest: sha256:308f4cd2414839b00119166f359a14cc6430df7ee469e2069829e683b8a464c6
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
diff --git a/report_substitute/__manifest__.py b/report_substitute/__manifest__.py
index 24a5108e4c..6205346624 100644
--- a/report_substitute/__manifest__.py
+++ b/report_substitute/__manifest__.py
@@ -6,7 +6,7 @@
"summary": """
This module allows to create substitution rules for report actions.
""",
- "version": "16.0.1.1.1",
+ "version": "16.0.1.1.2",
"license": "AGPL-3",
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine",
diff --git a/report_substitute/models/ir_actions_report.py b/report_substitute/models/ir_actions_report.py
index a7641449b3..bec78b769c 100644
--- a/report_substitute/models/ir_actions_report.py
+++ b/report_substitute/models/ir_actions_report.py
@@ -57,13 +57,28 @@ def _render(self, report_ref, res_ids, data=None):
substitution_report.report_name, res_ids, data=data
)
- def _render_qweb_pdf(self, report_ref, res_ids=None, data=None):
- report = self._get_report(report_ref)
- substitution_report = report.get_substitution_report(res_ids)
+ def _render_qweb_pdf_substitution(
+ self, substitution_report, res_ids=None, data=None
+ ):
+ """Hook to render substitution reports with another report_type.
+
+ Return a ``(content, report_type)`` tuple, or ``None`` to fall
+ back to rendering the original report.
+ """
if substitution_report.filtered(lambda r: r.report_type == "qweb-pdf"):
return super(IrActionReport, self)._render_qweb_pdf(
substitution_report, res_ids=res_ids, data=data
)
+ return None
+
+ def _render_qweb_pdf(self, report_ref, res_ids=None, data=None):
+ report = self._get_report(report_ref)
+ substitution_report = report.get_substitution_report(res_ids)
+ result = self._render_qweb_pdf_substitution(
+ substitution_report, res_ids=res_ids, data=data
+ )
+ if result is not None:
+ return result
return super(IrActionReport, self)._render_qweb_pdf(
report_ref, res_ids=res_ids, data=data
)
diff --git a/report_substitute/static/description/index.html b/report_substitute/static/description/index.html
index 9dde3eac77..dfd003c5f4 100644
--- a/report_substitute/static/description/index.html
+++ b/report_substitute/static/description/index.html
@@ -372,7 +372,7 @@
This module allows you to create substitution rules for report actions. diff --git a/report_substitute/tests/test_report_substitute.py b/report_substitute/tests/test_report_substitute.py index 88796624de..911fec2ab4 100644 --- a/report_substitute/tests/test_report_substitute.py +++ b/report_substitute/tests/test_report_substitute.py @@ -103,3 +103,14 @@ def test_substitution_infinite_loop(self): ).id, } ) + + def test_render_qweb_pdf_falls_back_for_non_qweb_substitute(self): + # A substitute whose report_type is not qweb-pdf cannot be rendered + # by _render_qweb_pdf, which should fall back to the original report. + self.substitution_rule.substitution_action_report_id.report_type = "qweb-text" + res = str( + self.action_report._render_qweb_pdf( + self.action_report.report_name, res_ids=self.res_ids + )[0] + ) + self.assertNotIn('