pull/859/merge
Iván Todorovich 2024-03-13 12:23:35 -06:00 committed by GitHub
commit ade1a89eb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 228 additions and 0 deletions

View File

@ -0,0 +1,111 @@
============================================
Report Wkhtmltopdf Paperformat from Template
============================================
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f51a84a5c23884b0f3e2f1eea0f66515c07344324f3dab70449ea0b437b66c17
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/16.0/report_wkhtmltopdf_paperformat_from_template
:alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/reporting-engine-16-0/reporting-engine-16-0-report_wkhtmltopdf_paperformat_from_template
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=16.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
This is a technical module that allows to force a paperformat directly from the
report QWeb template definition.
This is useful in situations where the report content is dynamically chosen, depending
on some record conditions, and a different paperformat needs to be used for each.
In core, Odoo already allows to overwrite some paperformat values like the ``margin-top``,
``header-spacing``, etc.. through special ``data-report-*`` attributes in the root ``html``
tag of the report QWeb template. This module extends this feature to allow to overwrite
the paperformat itself.
**Table of contents**
.. contents::
:local:
Usage
=====
In a report QWeb template, set the ``data_report_paperformat`` variable to the desired
paperformat ``xmlid``.
For example:
.. code-block:: xml
<template id="report_invoice" inherit_id="account.report_invoice">
<xpath expr="//t[@t-call='web.html_container']" position="before">
<t t-set="data_report_paperformat">my_module.paperformat_custom</t>
</xpath>
</template>
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`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**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Camptocamp
Contributors
~~~~~~~~~~~~
* `Camptocamp <https://www.camptocamp.com>`_
* Iván Todorovich <ivan.todorovich@camptocamp.com>
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
.. |maintainer-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px
:target: https://github.com/ivantodorovich
:alt: ivantodorovich
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-ivantodorovich|
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.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -0,0 +1 @@
from . import models

View File

@ -0,0 +1,15 @@
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Report Wkhtmltopdf Paperformat from Template",
"summary": "Force the paperformat directly in the specific paperformat args",
"version": "16.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["ivantodorovich"],
"website": "https://github.com/OCA/reporting-engine",
"license": "AGPL-3",
"category": "Technical",
"depends": ["web"],
"data": ["views/report_layout.xml"],
}

View File

@ -0,0 +1 @@
from . import ir_actions_report

View File

@ -0,0 +1,44 @@
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, models
class IrActionsReport(models.Model):
_inherit = "ir.actions.report"
@api.model
def get_paperformat(self):
# OVERRIDE to allow to define paperformat via context
if paperformat_id := self.env.context.get("paperformat_id"):
return self.env["report.paperformat"].browse(paperformat_id)
return super().get_paperformat()
@api.model
def _run_wkhtmltopdf(
self,
bodies,
report_ref=False,
header=None,
footer=None,
landscape=False,
specific_paperformat_args=None,
set_viewport_size=False,
):
# OVERRIDE to allow to define paperformat via context
if specific_paperformat_args is None:
specific_paperformat_args = {}
if paperformat_xml_id := specific_paperformat_args.get(
"data-report-paperformat"
):
paperformat_id = self.env.ref(paperformat_xml_id).id
self = self.with_context(paperformat_id=paperformat_id)
return super(IrActionsReport, self)._run_wkhtmltopdf(
bodies,
report_ref=report_ref,
header=header,
footer=footer,
landscape=landscape,
specific_paperformat_args=specific_paperformat_args,
set_viewport_size=set_viewport_size,
)

View File

@ -0,0 +1,3 @@
* `Camptocamp <https://www.camptocamp.com>`_
* Iván Todorovich <ivan.todorovich@camptocamp.com>

View File

@ -0,0 +1,10 @@
This is a technical module that allows to force a paperformat directly from the
report QWeb template definition.
This is useful in situations where the report content is dynamically chosen, depending
on some record conditions, and a different paperformat needs to be used for each.
In core, Odoo already allows to overwrite some paperformat values like the ``margin-top``,
``header-spacing``, etc.. through special ``data-report-*`` attributes in the root ``html``
tag of the report QWeb template. This module extends this feature to allow to overwrite
the paperformat itself.

View File

@ -0,0 +1,12 @@
In a report QWeb template, set the ``data_report_paperformat`` variable to the desired
paperformat ``xmlid``.
For example:
.. code-block:: xml
<template id="report_invoice" inherit_id="account.report_invoice">
<xpath expr="//t[@t-call='web.html_container']" position="before">
<t t-set="data_report_paperformat">my_module.paperformat_custom</t>
</xpath>
</template>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<template id="report_layout" inherit_id="web.report_layout">
<html position="attributes">
<attribute
name="t-att-data-report-paperformat"
>data_report_paperformat</attribute>
</html>
</template>
<template id="report_preview_layout" inherit_id="web.report_preview_layout">
<html position="attributes">
<attribute
name="t-att-data-report-paperformat"
>data_report_paperformat</attribute>
</html>
</template>
</odoo>

View File

@ -0,0 +1 @@
../../../../report_wkhtmltopdf_paperformat_from_template

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)