Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Apr 25, 2023
1 parent 4aec4ef commit 8ecb3a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
9 changes: 5 additions & 4 deletions report_qweb_custom_renderer/models/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import time

from odoo import api, fields, models
from odoo import fields, models

_logger = logging.getLogger(__name__)

Expand All @@ -17,8 +17,7 @@ class IrActionsReport(models.Model):
string="PDF Engine",
)

@api.multi
def render_qweb_pdf(self, res_ids=None, data=None):
def _render_qweb_pdf(self, report_ref, res_ids=None, data=None):
qweb_pdf_engine = "wkhtmltopdf"
qweb_pdf_engine = "weasyprint"

Expand All @@ -27,12 +26,14 @@ def render_qweb_pdf(self, res_ids=None, data=None):
_logger.info("========================================")
time_1 = time.time()
if qweb_pdf_engine == "wkhtmltopdf":
result = super(IrActionsReport, self).render_qweb_pdf(
result = super()._render_qweb_pdf(
report_ref,
res_ids=res_ids,
data=data,
)
else:
result = getattr(self, "_render_qweb_pdf_%s" % qweb_pdf_engine)(
report_ref,
res_ids=res_ids,
data=data,
)
Expand Down
18 changes: 13 additions & 5 deletions report_qweb_weasyprint_renderer/models/ir_actions_report.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# 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
import logging

from odoo import fields, models

try:
from weasyprint import HTML
except ImportError:
HTML = None

_logger = logging.getLogger(__name__)


class IrActionsReport(models.Model):
_inherit = "ir.actions.report"
Expand All @@ -15,17 +19,21 @@ class IrActionsReport(models.Model):
selection_add=[("weasyprint", "WeasyPrint")],
)

@api.multi
def _render_qweb_pdf_weasyprint(self, res_ids=None, data=None):
def _render_qweb_pdf_weasyprint(self, report_ref, 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]
html = self.with_context(**context)._render_qweb_html(
report_ref, res_ids, data=data
)
with open("/tmp/tralala_weasyprint.html", "wb+") as f:
f.write(html[0])

return (
HTML(
string=html,
string=html[0],
# 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"),
Expand Down

0 comments on commit 8ecb3a5

Please sign in to comment.