Skip to content

Commit 9456186

Browse files
[ADD] report_wkhtmltopdf_paperformat_from_template
1 parent b892776 commit 9456186

File tree

9 files changed

+204
-0
lines changed

9 files changed

+204
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
============================================
2+
Report Wkhtmltopdf Paperformat from Template
3+
============================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:f51a84a5c23884b0f3e2f1eea0f66515c07344324f3dab70449ea0b437b66c17
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
20+
:target: https://github.com/OCA/reporting-engine/tree/16.0/report_wkhtmltopdf_paperformat_from_template
21+
:alt: OCA/reporting-engine
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/reporting-engine-16-0/reporting-engine-16-0-report_wkhtmltopdf_paperformat_from_template
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=16.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This is a technical module that allows to force a paperformat directly from the
32+
report QWeb template definition.
33+
34+
This is useful in situations where the report content is dynamically chosen, depending
35+
on some record conditions, and a different paperformat needs to be used for each.
36+
37+
In core, Odoo already allows to overwrite some paperformat values like the ``margin-top``,
38+
``header-spacing``, etc.. through special ``data-report-*`` attributes in the root ``html``
39+
tag of the report QWeb template. This module extends this feature to allow to overwrite
40+
the paperformat itself.
41+
42+
**Table of contents**
43+
44+
.. contents::
45+
:local:
46+
47+
Usage
48+
=====
49+
50+
In a report QWeb template, set the ``data_report_paperformat`` variable to the desired
51+
paperformat ``xmlid``.
52+
53+
For example:
54+
55+
.. code-block:: xml
56+
57+
<template id="report_invoice" inherit_id="account.report_invoice">
58+
<xpath expr="//t[@t-call='web.html_container']" position="before">
59+
<t t-set="data_report_paperformat">my_module.paperformat_custom</t>
60+
</xpath>
61+
</template>
62+
63+
Bug Tracker
64+
===========
65+
66+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
67+
In case of trouble, please check there if your issue has already been reported.
68+
If you spotted it first, help us to smash it by providing a detailed and welcomed
69+
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_wkhtmltopdf_paperformat_from_template%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
70+
71+
Do not contact contributors directly about support or help with technical issues.
72+
73+
Credits
74+
=======
75+
76+
Authors
77+
~~~~~~~
78+
79+
* Camptocamp
80+
81+
Contributors
82+
~~~~~~~~~~~~
83+
84+
* `Camptocamp <https://www.camptocamp.com>`_
85+
86+
* Iván Todorovich <ivan.todorovich@camptocamp.com>
87+
88+
Maintainers
89+
~~~~~~~~~~~
90+
91+
This module is maintained by the OCA.
92+
93+
.. image:: https://odoo-community.org/logo.png
94+
:alt: Odoo Community Association
95+
:target: https://odoo-community.org
96+
97+
OCA, or the Odoo Community Association, is a nonprofit organization whose
98+
mission is to support the collaborative development of Odoo features and
99+
promote its widespread use.
100+
101+
.. |maintainer-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px
102+
:target: https://github.com/ivantodorovich
103+
:alt: ivantodorovich
104+
105+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
106+
107+
|maintainer-ivantodorovich|
108+
109+
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/16.0/report_wkhtmltopdf_paperformat_from_template>`_ project on GitHub.
110+
111+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
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)