diff --git a/web_export_html_as_text/README.rst b/web_export_html_as_text/README.rst new file mode 100644 index 000000000000..ccf48360dcd0 --- /dev/null +++ b/web_export_html_as_text/README.rst @@ -0,0 +1,112 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +======================= +Web Export Html As Text +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b2b5034997d831fbed7595dbc658362d36e20a0aef213a81fa6c801ab7c973ec + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/19.0/web_export_html_as_text + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-19-0/web-19-0-web_export_html_as_text + :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/web&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows exporting HTML fields as plain text. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To export HTML fields as plain text: + +- Open any list view. +- Select the records, then click Export under the Action menu. +- Enable "Export HTML as text" in the export dialog. + +Note: This setting will apply to all HTML fields exported in the current +export dialog. + +Known issues / Roadmap +====================== + +Lists (numbered, bullets, checklists) and rich formatting (bold, +italics, underline, colors, fonts, alignment) from Odoo HTML fields are +not preserved in exports; all are simplified to plain text. + +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 +------- + +* Quartile + +Contributors +------------ + +- `Quartile `__ + + - Aung Ko Ko Lin + +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-yostashiro| image:: https://github.com/yostashiro.png?size=40px + :target: https://github.com/yostashiro + :alt: yostashiro +.. |maintainer-AungKoKoLin1997| image:: https://github.com/AungKoKoLin1997.png?size=40px + :target: https://github.com/AungKoKoLin1997 + :alt: AungKoKoLin1997 + +Current `maintainers `__: + +|maintainer-yostashiro| |maintainer-AungKoKoLin1997| + +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_export_html_as_text/__init__.py b/web_export_html_as_text/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/web_export_html_as_text/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/web_export_html_as_text/__manifest__.py b/web_export_html_as_text/__manifest__.py new file mode 100644 index 000000000000..d0c3510fde5d --- /dev/null +++ b/web_export_html_as_text/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Web Export Html As Text", + "version": "19.0.1.0.0", + "website": "https://github.com/OCA/web", + "author": "Quartile, Odoo Community Association (OCA)", + "category": "Tools", + "license": "AGPL-3", + "depends": ["base"], + "assets": { + "web.assets_backend": [ + "web_export_html_as_text/static/src/js/*.esm.js", + "web_export_html_as_text/static/src/xml/*.xml", + ], + }, + "maintainers": ["yostashiro", "AungKoKoLin1997"], + "installable": True, +} diff --git a/web_export_html_as_text/i18n/it.po b/web_export_html_as_text/i18n/it.po new file mode 100644 index 000000000000..68aa5bd7f825 --- /dev/null +++ b/web_export_html_as_text/i18n/it.po @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_export_html_as_text +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-09-18 15:59+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.4\n" + +#. module: web_export_html_as_text +#: model:ir.model,name:web_export_html_as_text.model_base +msgid "Base" +msgstr "Base" + +#. module: web_export_html_as_text +#. odoo-javascript +#: code:addons/web_export_html_as_text/static/src/xml/export_dialog.xml:0 +#, python-format +msgid "Export HTML as text" +msgstr "Esporta HTML come testo" diff --git a/web_export_html_as_text/i18n/web_export_html_as_text.pot b/web_export_html_as_text/i18n/web_export_html_as_text.pot new file mode 100644 index 000000000000..ebf96905423b --- /dev/null +++ b/web_export_html_as_text/i18n/web_export_html_as_text.pot @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_export_html_as_text +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_export_html_as_text +#: model:ir.model,name:web_export_html_as_text.model_base +msgid "Base" +msgstr "" + +#. module: web_export_html_as_text +#. odoo-javascript +#: code:addons/web_export_html_as_text/static/src/xml/export_dialog.xml:0 +#, python-format +msgid "Export HTML as text" +msgstr "" diff --git a/web_export_html_as_text/models/__init__.py b/web_export_html_as_text/models/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/web_export_html_as_text/models/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/web_export_html_as_text/models/models.py b/web_export_html_as_text/models/models.py new file mode 100644 index 000000000000..f7f4c4a1584b --- /dev/null +++ b/web_export_html_as_text/models/models.py @@ -0,0 +1,48 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models +from odoo.models import fix_import_export_id_paths +from odoo.tools import html2plaintext + + +def _is_html_path(model, path): + if not path or path[0] in ("id", ".id"): + return False + cur_model = model + for i, p in enumerate(path): + fld = cur_model._fields.get(p) + if not fld: + return False + last = i == len(path) - 1 + if last: + return getattr(fld, "type", None) == "html" + if getattr(fld, "relational", False): + cur_model = model.env[fld.comodel_name] + else: + return False + return False + + +class BaseExportHtmlAsText(models.AbstractModel): + _inherit = "base" + + @api.model + def export_data(self, fields_to_export): + res = super().export_data(fields_to_export) + if not self.env.context.get("export_html_as_text"): + return res + datas = res.get("datas", []) + if not datas: + return res + fields_to_export = [fix_import_export_id_paths(f) for f in fields_to_export] + html_indexes = [ + i for i, p in enumerate(fields_to_export) if _is_html_path(self, p) + ] + if not html_indexes: + return res + for row in datas: + for idx in html_indexes: + if isinstance(row[idx], str) and row[idx]: + row[idx] = html2plaintext(row[idx]) + return res diff --git a/web_export_html_as_text/pyproject.toml b/web_export_html_as_text/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/web_export_html_as_text/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/web_export_html_as_text/readme/CONFIGURE.md b/web_export_html_as_text/readme/CONFIGURE.md new file mode 100644 index 000000000000..9cccede66305 --- /dev/null +++ b/web_export_html_as_text/readme/CONFIGURE.md @@ -0,0 +1,8 @@ +To export HTML fields as plain text: + +- Open any list view. +- Select the records, then click Export under the Action menu. +- Enable "Export HTML as text" in the export dialog. + +Note: This setting will apply to all HTML fields exported in the current +export dialog. diff --git a/web_export_html_as_text/readme/CONTRIBUTORS.md b/web_export_html_as_text/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..e49c3c4ef24b --- /dev/null +++ b/web_export_html_as_text/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Quartile](https://www.quartile.co) + - Aung Ko Ko Lin diff --git a/web_export_html_as_text/readme/DESCRIPTION.md b/web_export_html_as_text/readme/DESCRIPTION.md new file mode 100644 index 000000000000..effb61f5feca --- /dev/null +++ b/web_export_html_as_text/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows exporting HTML fields as plain text. diff --git a/web_export_html_as_text/readme/ROADMAP.md b/web_export_html_as_text/readme/ROADMAP.md new file mode 100644 index 000000000000..79a6a6cb17c8 --- /dev/null +++ b/web_export_html_as_text/readme/ROADMAP.md @@ -0,0 +1,3 @@ +Lists (numbered, bullets, checklists) and rich formatting (bold, +italics, underline, colors, fonts, alignment) from Odoo HTML fields are +not preserved in exports; all are simplified to plain text. diff --git a/web_export_html_as_text/static/description/icon.png b/web_export_html_as_text/static/description/icon.png new file mode 100644 index 000000000000..1dcc49c24f36 Binary files /dev/null and b/web_export_html_as_text/static/description/icon.png differ diff --git a/web_export_html_as_text/static/description/index.html b/web_export_html_as_text/static/description/index.html new file mode 100644 index 000000000000..b77f74d977a7 --- /dev/null +++ b/web_export_html_as_text/static/description/index.html @@ -0,0 +1,453 @@ + + + + + +Codestin Search App + + + +
+ + + +Odoo Community Association + +
+

Web Export Html As Text

+ +

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

+

This module allows exporting HTML fields as plain text.

+

Table of contents

+ +
+

Configuration

+

To export HTML fields as plain text:

+
    +
  • Open any list view.
  • +
  • Select the records, then click Export under the Action menu.
  • +
  • Enable “Export HTML as text” in the export dialog.
  • +
+

Note: This setting will apply to all HTML fields exported in the current +export dialog.

+
+
+

Known issues / Roadmap

+

Lists (numbered, bullets, checklists) and rich formatting (bold, +italics, underline, colors, fonts, alignment) from Odoo HTML fields are +not preserved in exports; all are simplified to plain text.

+
+
+

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

+
    +
  • Quartile
  • +
+
+
+

Contributors

+ +
+
+

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.

+

Current maintainers:

+

yostashiro AungKoKoLin1997

+

This module is part of the OCA/web project on GitHub.

+

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

+
+
+
+
+ + diff --git a/web_export_html_as_text/static/src/js/export_html_to_text.esm.js b/web_export_html_as_text/static/src/js/export_html_to_text.esm.js new file mode 100644 index 000000000000..784ffa49a3b1 --- /dev/null +++ b/web_export_html_as_text/static/src/js/export_html_to_text.esm.js @@ -0,0 +1,34 @@ +/** @odoo-module **/ +import {patch} from "@web/core/utils/patch"; +import {ExportDataDialog} from "@web/views/view_dialogs/export_data_dialog"; + +patch(ExportDataDialog.prototype, { + setup() { + super.setup(); + const originalDownload = this.props.download; + this.props.download = async (fields, import_compat, format) => { + const dialog = document.querySelector(".o_export_data_dialog"); + const elAnywhere = document.querySelector("#o-export-html-as-text"); + const el = dialog?.querySelector("#o-export-html-as-text") || elAnywhere; + const exportHtmlAsText = Boolean(el && el.checked); + const {root} = this.props; + const ctx = root.context; + const hadKey = Object.prototype.hasOwnProperty.call( + ctx, + "export_html_as_text" + ); + const prev = ctx.export_html_as_text; + + ctx.export_html_as_text = exportHtmlAsText; + try { + return await originalDownload(fields, import_compat, format); + } finally { + if (hadKey) { + ctx.export_html_as_text = prev; + } else { + delete ctx.export_html_as_text; + } + } + }; + }, +}); diff --git a/web_export_html_as_text/static/src/xml/export_dialog.xml b/web_export_html_as_text/static/src/xml/export_dialog.xml new file mode 100644 index 000000000000..b24a8f214b2b --- /dev/null +++ b/web_export_html_as_text/static/src/xml/export_dialog.xml @@ -0,0 +1,17 @@ + + + + +
+ + +
+
+
+
diff --git a/web_export_html_as_text/tests/__init__.py b/web_export_html_as_text/tests/__init__.py new file mode 100644 index 000000000000..0913ff5ffd8d --- /dev/null +++ b/web_export_html_as_text/tests/__init__.py @@ -0,0 +1 @@ +from . import test_export_html_text diff --git a/web_export_html_as_text/tests/test_export_html_text.py b/web_export_html_as_text/tests/test_export_html_text.py new file mode 100644 index 000000000000..1b253991adef --- /dev/null +++ b/web_export_html_as_text/tests/test_export_html_text.py @@ -0,0 +1,44 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo_test_helper import FakeModelLoader + +from odoo.tests.common import TransactionCase + + +class TestExportHtmlText(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.loader = FakeModelLoader(cls.env, cls.__module__) + cls.loader.backup_registry() + from .test_models import TestExportHtmlText + + cls.loader.update_registry((TestExportHtmlText,)) + cls.test_model = cls.env.ref( + "web_export_html_as_text.model_test_export_html_text" + ) + cls.html_field = cls.env["ir.model.fields"]._get( + "test.export.html.text", "narration" + ) + cls.record = cls.env["test.export.html.text"].create( + { + "name": "Test 1", + "narration": "

This is a test HTML content.

", + } + ) + + @classmethod + def tearDownClass(cls): + cls.loader.restore_registry() + super().tearDownClass() + + def test_convert_to_export_html(self): + res = self.record.export_data(["narration"]) + self.assertEqual( + res["datas"][0][0], "

This is a test HTML content.

" + ) + res = self.record.with_context(export_html_as_text=True).export_data( + ["narration"] + ) + self.assertEqual(res["datas"][0][0], "This is a *test* HTML content.") diff --git a/web_export_html_as_text/tests/test_models.py b/web_export_html_as_text/tests/test_models.py new file mode 100644 index 000000000000..63239c5da089 --- /dev/null +++ b/web_export_html_as_text/tests/test_models.py @@ -0,0 +1,11 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class TestExportHtmlText(models.Model): + _name = "test.export.html.text" + + name = fields.Char() + narration = fields.Html()