diff --git a/requirements.txt b/requirements.txt index e02b3dd1f6..68f49df946 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,10 @@ # generated from manifests external_dependencies cryptography +emoji_data_python endesive ; python_version >= '3.12' endesive<=2.18.5 ; python_version < '3.12' mock openpyxl py3o.formats py3o.template +twemoji_api diff --git a/setup/web_emojis/odoo/addons/web_emojis b/setup/web_emojis/odoo/addons/web_emojis new file mode 120000 index 0000000000..1a65a39efb --- /dev/null +++ b/setup/web_emojis/odoo/addons/web_emojis @@ -0,0 +1 @@ +../../../../web_emojis \ No newline at end of file diff --git a/setup/web_emojis/setup.py b/setup/web_emojis/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/web_emojis/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_emojis/README.rst b/web_emojis/README.rst new file mode 100644 index 0000000000..115b9b3a1d --- /dev/null +++ b/web_emojis/README.rst @@ -0,0 +1,79 @@ +========== +Web Emojis +========== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:139a034a9bcf6e171e22ea5c7c1350d3bfd964d77b210514b7507896459ae108 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/web_emojis + :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-web_emojis + :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| + +Replaces emojis with Twemoji images in PDF reports. + +Emojis cannot be rendered by wkhtmltopdf. This module automatically converts +them to img tags pointing to Twemoji images before PDF generation. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Lambdao + +Contributors +~~~~~~~~~~~~ + +* len + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_emojis/__init__.py b/web_emojis/__init__.py new file mode 100644 index 0000000000..903c73f48e --- /dev/null +++ b/web_emojis/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2026 Lambdao +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/web_emojis/__manifest__.py b/web_emojis/__manifest__.py new file mode 100644 index 0000000000..e560d1030e --- /dev/null +++ b/web_emojis/__manifest__.py @@ -0,0 +1,32 @@ +# Copyright 2026 Lambdao +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +# workaround module for: +# https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2913 +# wkhtmltopdf supports some emojis in black & white only, and color +# emojis aren't supported at all. +# For example, ⚠️ would be rendered as simple line drawing in pdf, +# and not as a colorful yellow warning sign. +# Meanwhile, πŸ‡«πŸ‡· would render as missing glyphs instead of the French flag. +# So it's not perfect as true emoji support would mean that copy-paste +# would work while this is not the case with this workaround. + + +{ + "name": "Web Emojis", + "summary": """ +Replaces emojis with Twemoji images in PDF reports. + +Emojis cannot be rendered by wkhtmltopdf. This module automatically converts +them to img tags pointing to Twemoji images before PDF generation. + """, + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Lambdao, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/reporting-engine", + "category": "Technical", + "depends": ["base"], + "external_dependencies": {"python": ["emoji_data_python", "twemoji_api"]}, + "demo": ["report/demo_report.xml"], + "installable": True, +} diff --git a/web_emojis/models/__init__.py b/web_emojis/models/__init__.py new file mode 100644 index 0000000000..00cc055791 --- /dev/null +++ b/web_emojis/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2026 Lambdao +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import ir_actions_report diff --git a/web_emojis/models/ir_actions_report.py b/web_emojis/models/ir_actions_report.py new file mode 100644 index 0000000000..50848d8486 --- /dev/null +++ b/web_emojis/models/ir_actions_report.py @@ -0,0 +1,62 @@ +# Copyright 2026 Lambdao +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging + +from emoji_data_python import get_emoji_regex +from twemoji_api import get_emoji_url + +from odoo import models + +_logger = logging.getLogger(__name__) + + +def _emoji_to_img(match): + """Replace an emoji match with an img tag.""" + emoji = match.group(0) + try: + url = get_emoji_url(emoji) + except ValueError: + return emoji + # flake8: noqa + return ( + f'{emoji}' + ) + + +def replace_emojis(html): + """Replace emojis in HTML with Twemoji img tags.""" + if not html: + return html + return get_emoji_regex().sub(_emoji_to_img, html) + + +class IrActionsReport(models.Model): + _inherit = "ir.actions.report" + + def _run_wkhtmltopdf( + self, + bodies, + report_ref=False, + header=None, + footer=None, + landscape=False, + specific_paperformat_args=None, + set_viewport_size=False, + ): + bodies = [replace_emojis(body) for body in bodies] + # headers and footers are already problematic enough + # if header: + # header = replace_emojis(header) + # if footer: + # footer = replace_emojis(footer) + return super()._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, + ) diff --git a/web_emojis/readme/CONTRIBUTORS.rst b/web_emojis/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..d7d5985481 --- /dev/null +++ b/web_emojis/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* len diff --git a/web_emojis/readme/DESCRIPTION.rst b/web_emojis/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..9b641ba3bd --- /dev/null +++ b/web_emojis/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +Replaces emojis with Twemoji images in PDF reports. + +Emojis cannot be rendered by wkhtmltopdf. This module automatically converts +them to img tags pointing to Twemoji images before PDF generation. diff --git a/web_emojis/report/demo_report.xml b/web_emojis/report/demo_report.xml new file mode 100644 index 0000000000..47dfda5d03 --- /dev/null +++ b/web_emojis/report/demo_report.xml @@ -0,0 +1,53 @@ + + + + + + + Emoji Demo + res.company + qweb-pdf + web_emojis.report_emoji_demo_document + web_emojis.report_emoji_demo_document + + report + + diff --git a/web_emojis/static/description/index.html b/web_emojis/static/description/index.html new file mode 100644 index 0000000000..608a60a038 --- /dev/null +++ b/web_emojis/static/description/index.html @@ -0,0 +1,425 @@ + + + + + +Web Emojis + + + +
+

Web Emojis

+ + +

Beta License: AGPL-3 OCA/reporting-engine Translate me on Weblate Try me on Runboat

+

Replaces emojis with Twemoji images in PDF reports.

+

Emojis cannot be rendered by wkhtmltopdf. This module automatically converts +them to img tags pointing to Twemoji images before PDF generation.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Lambdao
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ +