From abd59c1a9b7ce774c131c884b9900c10bba7938d Mon Sep 17 00:00:00 2001 From: ArnauCForgeFlow Date: Tue, 19 Nov 2024 16:36:15 +0100 Subject: [PATCH] [ADD] web_excel_export_dynamic_expand --- .../addons/web_excel_export_dynamic_expand | 1 + .../web_excel_export_dynamic_expand/setup.py | 6 + web_excel_export_dynamic_expand/README.rst | 78 ++++ web_excel_export_dynamic_expand/__init__.py | 1 + .../__manifest__.py | 18 + .../controllers/__init__.py | 1 + .../controllers/excel_export.py | 38 ++ .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 2 + .../static/description/index.html | 424 ++++++++++++++++++ .../static/src/js/data_export.esm.js | 24 + 11 files changed, 595 insertions(+) create mode 120000 setup/web_excel_export_dynamic_expand/odoo/addons/web_excel_export_dynamic_expand create mode 100644 setup/web_excel_export_dynamic_expand/setup.py create mode 100644 web_excel_export_dynamic_expand/README.rst create mode 100644 web_excel_export_dynamic_expand/__init__.py create mode 100644 web_excel_export_dynamic_expand/__manifest__.py create mode 100644 web_excel_export_dynamic_expand/controllers/__init__.py create mode 100644 web_excel_export_dynamic_expand/controllers/excel_export.py create mode 100644 web_excel_export_dynamic_expand/readme/CONTRIBUTORS.rst create mode 100644 web_excel_export_dynamic_expand/readme/DESCRIPTION.rst create mode 100644 web_excel_export_dynamic_expand/static/description/index.html create mode 100644 web_excel_export_dynamic_expand/static/src/js/data_export.esm.js diff --git a/setup/web_excel_export_dynamic_expand/odoo/addons/web_excel_export_dynamic_expand b/setup/web_excel_export_dynamic_expand/odoo/addons/web_excel_export_dynamic_expand new file mode 120000 index 000000000..a71d1d1a6 --- /dev/null +++ b/setup/web_excel_export_dynamic_expand/odoo/addons/web_excel_export_dynamic_expand @@ -0,0 +1 @@ +../../../../web_excel_export_dynamic_expand \ No newline at end of file diff --git a/setup/web_excel_export_dynamic_expand/setup.py b/setup/web_excel_export_dynamic_expand/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_excel_export_dynamic_expand/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_excel_export_dynamic_expand/README.rst b/web_excel_export_dynamic_expand/README.rst new file mode 100644 index 000000000..d39347b2d --- /dev/null +++ b/web_excel_export_dynamic_expand/README.rst @@ -0,0 +1,78 @@ +=============================== +Web Excel Export Dynamic Expand +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ee1ab26433dfe8bd1d3489d5051728dd84a7583b5dc50d0d47a95e71b1e28c67 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/15.0/web_excel_export_dynamic_expand + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_excel_export_dynamic_expand + :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=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +When exporting a tree view to an Excel file, you can decide if you want to expor only +the main groups or the full tree, depending if all groups are collapsed, or there is one open. + +**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 +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Arnau Cruz + + +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/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_excel_export_dynamic_expand/__init__.py b/web_excel_export_dynamic_expand/__init__.py new file mode 100644 index 000000000..e046e49fb --- /dev/null +++ b/web_excel_export_dynamic_expand/__init__.py @@ -0,0 +1 @@ +from . import controllers diff --git a/web_excel_export_dynamic_expand/__manifest__.py b/web_excel_export_dynamic_expand/__manifest__.py new file mode 100644 index 000000000..77c1a2f1b --- /dev/null +++ b/web_excel_export_dynamic_expand/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright (C) 2024 - ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Web Excel Export Dynamic Expand", + "summary": "Export collapsed groups or the full tree, based on its view.", + "version": "15.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "license": "AGPL-3", + "depends": ["web"], + "data": [], + "assets": { + "web.assets_backend": [ + "web_excel_export_dynamic_expand/static/src/js/data_export.esm.js", + ], + }, +} diff --git a/web_excel_export_dynamic_expand/controllers/__init__.py b/web_excel_export_dynamic_expand/controllers/__init__.py new file mode 100644 index 000000000..14a746891 --- /dev/null +++ b/web_excel_export_dynamic_expand/controllers/__init__.py @@ -0,0 +1 @@ +from . import excel_export diff --git a/web_excel_export_dynamic_expand/controllers/excel_export.py b/web_excel_export_dynamic_expand/controllers/excel_export.py new file mode 100644 index 000000000..4c702f61b --- /dev/null +++ b/web_excel_export_dynamic_expand/controllers/excel_export.py @@ -0,0 +1,38 @@ +# Copyright 2024 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import json +from collections import OrderedDict + +from odoo import http + +from odoo.addons.web.controllers.main import ExcelExport + + +class CustomGroupsTreeNode(ExcelExport): + @http.route("/web/export/xlsx", type="http", auth="user") + def index(self, data): + params = json.loads(data) + self.context = params.get("context", {}) + response = super().index(data) + return response + + @property + def context(self): + return self._context + + @context.setter + def context(self, value): + self._context = value + + def from_group_data(self, fields, groups): + collapse_groups = self.context.get("collapse_groups") + if collapse_groups: + for _child_key, child_node in groups.children.items(): + aggregated_values = child_node.aggregated_values + if child_node.children: + child_node.children = OrderedDict() + if child_node.data: + child_node.data = [] + child_node.aggregated_values = aggregated_values + return super().from_group_data(fields, groups) diff --git a/web_excel_export_dynamic_expand/readme/CONTRIBUTORS.rst b/web_excel_export_dynamic_expand/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..fd654f2a6 --- /dev/null +++ b/web_excel_export_dynamic_expand/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Arnau Cruz + diff --git a/web_excel_export_dynamic_expand/readme/DESCRIPTION.rst b/web_excel_export_dynamic_expand/readme/DESCRIPTION.rst new file mode 100644 index 000000000..9884f7cba --- /dev/null +++ b/web_excel_export_dynamic_expand/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +When exporting a tree view to an Excel file, you can decide if you want to export only +the main groups or the full tree, depending if all groups are collapsed, or there is one open. diff --git a/web_excel_export_dynamic_expand/static/description/index.html b/web_excel_export_dynamic_expand/static/description/index.html new file mode 100644 index 000000000..3284c2d17 --- /dev/null +++ b/web_excel_export_dynamic_expand/static/description/index.html @@ -0,0 +1,424 @@ + + + + + +Web Excel Export Dynamic Expand + + + +
+

Web Excel Export Dynamic Expand

+ + +

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

+

When exporting a tree view to an Excel file, you can decide if you want to expor only +the main groups or the full tree, depending if all groups are collapsed, or there is one open.

+

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

+
    +
  • ForgeFlow
  • +
+
+ +
+

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

+

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

+
+
+
+ + diff --git a/web_excel_export_dynamic_expand/static/src/js/data_export.esm.js b/web_excel_export_dynamic_expand/static/src/js/data_export.esm.js new file mode 100644 index 000000000..1b5862d96 --- /dev/null +++ b/web_excel_export_dynamic_expand/static/src/js/data_export.esm.js @@ -0,0 +1,24 @@ +/* Copyright 2024 Forgeflow + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ +odoo.define("web_excel_export_dynamic_expand.DataExport", function (require) { + var DataExport = require("web.DataExport"); + + DataExport.include({ + /** + * @override + */ + _exportData: function () { + var hasDataRow = $(".o_data_row").length > 0; + var hasGroup = $(".o_group_header").length > 0; + var collapseGroups = !hasDataRow && hasGroup; + + var originalGetContext = this.record.getContext; + this.record.getContext = function () { + var context = originalGetContext.call(this); + context.collapse_groups = collapseGroups; + return context; + }; + this._super(...arguments); + }, + }); +});