Skip to content

Commit

Permalink
[ADD] report_qweb_weasyprint_renderer
Browse files Browse the repository at this point in the history
fixes OCA#254
  • Loading branch information
hbrunn authored and legalsylvain committed Apr 25, 2023
1 parent 253ddbe commit fbc6704
Show file tree
Hide file tree
Showing 17 changed files with 742 additions and 0 deletions.
95 changes: 95 additions & 0 deletions report_qweb_weasyprint_renderer/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
========================
Weasyprint QWEB renderer
========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/12.0/report_qweb_weasyprint_renderer
: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-12-0/reporting-engine-12-0-report_qweb_weasyprint_renderer
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/143/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you to use `weasyprint <https://weasyprint.org>`_ to render PDFs, which allows for more print related HTML features than using Odoo's standard wkhtmltopdf.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to set ``qweb_pdf_engine`` to ``weasyprint``::

<record id="demo_report" model="ir.actions.report">
<field name="qweb_pdf_engine">weasyprint</field>
</record>

Known issues / Roadmap
======================

* add a compatibility layer to replace wkhtmltopdf
* support paper formats
* add some sensible templates for weasyprint specific internal and external layouts

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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_qweb_weasyprint_renderer%0Aversion:%2012.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
~~~~~~~

* Therp BV

Contributors
~~~~~~~~~~~~

* Holger Brunn <[email protected]>

Other credits
~~~~~~~~~~~~~

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
* `weasyprint <https://weasyprint.org>`_

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.

This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/12.0/report_qweb_weasyprint_renderer>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions report_qweb_weasyprint_renderer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models
23 changes: 23 additions & 0 deletions report_qweb_weasyprint_renderer/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Weasyprint QWEB renderer",
"version": "12.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Reporting",
"summary": "Use WeasyPrint to create PDFs",
"depends": [
'report_qweb_custom_renderer',
'web',
],
"demo": [
"demo/report.xml",
],
"data": [
'views/templates.xml',
],
"external_dependencies": {
'python': ['weasyprint'],
},
}
70 changes: 70 additions & 0 deletions report_qweb_weasyprint_renderer/demo/report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="view_demo_report_qweb">
<html>
<head>
<style type="text/css">
@page {
size: A4;
padding: 20px;
@top-center {
content: '<t t-esc="env.user.name" /> - ' string(title);
}
@bottom-center {
content: counter(page) ' of ' counter(pages);
}
}
h1 {
string-set: title content();
page-break-before: always;
}
h1:first-of-type {
page-break-before: avoid;
}
.desc {
white-space: pre-line;
font-family: monospace;
}
.index {
list-style: none;
padding-left: 0em;
}
.index li a {
text-decoration: none;
color: inherit;
}
.index li a::after {
content: target-counter(attr(href), page);
float: right;
}
.img {
margin: .1em;
float: right;
}
</style>
</head>
<body>
<h1>Index</h1>
<ul class="index">
<li t-foreach="docs" t-as="this">
<a t-attf-href="#chapter{{this.id}}" t-esc="this.shortdesc" />
</li>
</ul>
<t t-foreach="docs" t-as="this">
<h1 t-attf-id="chapter{{this.id}}" t-esc="this.shortdesc" />
<img class="img" t-attf-src="data:img/*;base64,{{this.icon_image}}" />
<div class="desc" t-esc="this.description" />
</t>
</body>
</html>
</template>
<report id="demo_report"
string="WeasyPrint demo report"
model="ir.module.module"
name="report_qweb_weasyprint_renderer.view_demo_report_qweb"
report_type="qweb-pdf"
/>
<record id="demo_report" model="ir.actions.report">
<field name="qweb_pdf_engine">weasyprint</field>
</record>
</odoo>
3 changes: 3 additions & 0 deletions report_qweb_weasyprint_renderer/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import ir_actions_report
32 changes: 32 additions & 0 deletions report_qweb_weasyprint_renderer/models/ir_actions_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
try:
from weasyprint import HTML
except ImportError:
HTML = None


class IrActionsReport(models.Model):
_inherit = 'ir.actions.report'

qweb_pdf_engine = fields.Selection(
selection_add=[('weasyprint', 'WeasyPrint')],
)

@api.multi
def _render_qweb_pdf_weasyprint(self, res_ids=None, data=None):
data = data or {}
data['enable_editor'] = False,
context = dict(self.env.context)
context['qweb_pdf_engine'] = 'weasyprint'

html = self.with_context(**context).render_qweb_html(
res_ids, data=data
)[0]
return HTML(
string=html,
# TODO: pass a custom url fetcher to never actually use the port
base_url=self.env['ir.config_parameter'].get_param('report.url') or
self.env['ir.config_parameter'].get_param('web.base.url'),
).write_pdf(), 'pdf'
1 change: 1 addition & 0 deletions report_qweb_weasyprint_renderer/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Holger Brunn <[email protected]>
2 changes: 2 additions & 0 deletions report_qweb_weasyprint_renderer/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
* `weasyprint <https://weasyprint.org>`_
1 change: 1 addition & 0 deletions report_qweb_weasyprint_renderer/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows you to use `weasyprint <https://weasyprint.org>`_ to render PDFs, which allows for more print related HTML features than using Odoo's standard wkhtmltopdf.
3 changes: 3 additions & 0 deletions report_qweb_weasyprint_renderer/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* add a compatibility layer to replace wkhtmltopdf
* support paper formats
* add some sensible templates for weasyprint specific internal and external layouts
5 changes: 5 additions & 0 deletions report_qweb_weasyprint_renderer/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To use this module, you need to set ``qweb_pdf_engine`` to ``weasyprint``::

<record id="demo_report" model="ir.actions.report">
<field name="qweb_pdf_engine">weasyprint</field>
</record>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fbc6704

Please sign in to comment.