Skip to content

Commit aac6c6f

Browse files
[ADD] report_wkhtmltopdf_paperformat_from_template
1 parent b892776 commit aac6c6f

File tree

8 files changed

+93
-0
lines changed

8 files changed

+93
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Report Wkhtmltopdf Paperformat from Template",
6+
"summary": "Force the paperformat directly in the specific paperformat args",
7+
"version": "16.0.1.0.0",
8+
"author": "Camptocamp, Odoo Community Association (OCA)",
9+
"maintainers": ["ivantodorovich"],
10+
"website": "https://github.com/OCA/reporting-engine",
11+
"license": "AGPL-3",
12+
"category": "Technical",
13+
"depends": ["web"],
14+
"data": ["views/report_layout.xml"],
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import ir_actions_report
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, models
5+
6+
7+
class IrActionsReport(models.Model):
8+
_inherit = "ir.actions.report"
9+
10+
@api.model
11+
def _build_wkhtmltopdf_args(
12+
self,
13+
paperformat_id,
14+
landscape,
15+
specific_paperformat_args=None,
16+
set_viewport_size=False,
17+
):
18+
# OVERRIDE to allow to force the paperformat directly in the specific paperformat args
19+
if specific_paperformat_args is None:
20+
specific_paperformat_args = {}
21+
if "data-report-paperformat" in specific_paperformat_args:
22+
paperformat_id = self.env.ref(
23+
specific_paperformat_args.get("data-report-paperformat")
24+
)
25+
return super()._build_wkhtmltopdf_args(
26+
paperformat_id, landscape, specific_paperformat_args, set_viewport_size
27+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* `Camptocamp <https://www.camptocamp.com>`_
2+
3+
* Iván Todorovich <ivan.todorovich@camptocamp.com>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
This is a technical module that allows to force a paperformat directly from the
2+
report QWeb template definition.
3+
4+
This is useful in situations where the report content is dynamically chosen, depending
5+
on some record conditions, and a different paperformat needs to be used for each.
6+
7+
In core, Odoo already allows to overwrite some paperformat values like the ``margin-top``,
8+
``header-spacing``, etc.. through special ``data-report-*`` attributes in the root ``html``
9+
tag of the report QWeb template. This module extends this feature to allow to overwrite
10+
the paperformat itself.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
In a report QWeb template, set the ``data_report_paperformat`` variable to the desired
2+
paperformat ``xmlid``.
3+
4+
For example:
5+
6+
.. code-block:: xml
7+
8+
<template id="report_invoice" inherit_id="account.report_invoice">
9+
<xpath expr="//t[@t-call='web.html_container']" position="before">
10+
<t t-set="data_report_paperformat">my_module.paperformat_custom</t>
11+
</xpath>
12+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!--
3+
Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
4+
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
5+
-->
6+
<odoo>
7+
8+
<template id="report_layout" inherit_id="web.report_layout">
9+
<html position="attributes">
10+
<attribute
11+
name="t-att-data-report-paperformat"
12+
>data_report_paperformat</attribute>
13+
</html>
14+
</template>
15+
16+
<template id="report_preview_layout" inherit_id="web.report_preview_layout">
17+
<html position="attributes">
18+
<attribute
19+
name="t-att-data-report-paperformat"
20+
>data_report_paperformat</attribute>
21+
</html>
22+
</template>
23+
24+
</odoo>

0 commit comments

Comments
 (0)