Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ addon | version | maintainers | summary
[web_editor_class_selector](web_editor_class_selector/) | 18.0.1.0.0 | <a href='https://github.com/carlos-lopez-tecnativa'><img src='https://github.com/carlos-lopez-tecnativa.png' width='32' height='32' style='border-radius:50%;' alt='carlos-lopez-tecnativa'/></a> | Web editor class selector
[web_editor_disable_chatgpt](web_editor_disable_chatgpt/) | 18.0.1.0.0 | | Web Disable ChatGPT
[web_environment_ribbon](web_environment_ribbon/) | 18.0.1.0.3 | | Web Environment Ribbon
[web_excel_export_dynamic_expand](web_excel_export_dynamic_expand/) | 18.0.1.0.0 | | Export collapsed groups or the full tree, based on its view.
[web_excel_export_dynamic_expand](web_excel_export_dynamic_expand/) | 18.0.1.1.0 | | Export collapsed groups or the full tree, based on its view.
[web_favicon](web_favicon/) | 18.0.1.0.1 | | Allows to set a custom shortcut icon (aka favicon)
[web_filter_header_button](web_filter_header_button/) | 18.0.1.0.0 | | Show selected filters as buttons in the control panel
[web_font_size_report_layout](web_font_size_report_layout/) | 18.0.1.0.0 | | Adds a font size selector (pt) to the Document Layout wizard
Expand Down
16 changes: 12 additions & 4 deletions web_excel_export_dynamic_expand/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Web Excel Export Dynamic Expand
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0ebaf3ae34e14b004119de667f5e9923e0e3cc6a0e57349fd4b860af03a2b9c2
!! source digest: sha256:ced8400976e85e06231ac225317538ade452c1b9cc5a427ad22ae7591ec2e9d1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -32,9 +32,16 @@ Web Excel Export Dynamic Expand

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

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.
When exporting a list view to an Excel file, the export mirrors the
current group expansion state. The number of group levels visible in the
UI determines how many levels are included in the export:

- All groups collapsed → only top-level group summary rows.
- N levels of groups expanded → N levels of group summary rows, each
with its aggregated values but no further detail.
- All levels expanded → full export including individual records.

This works with any number of Group By filters applied simultaneously.

**Table of contents**

Expand Down Expand Up @@ -63,6 +70,7 @@ Contributors
------------

- Arnau Cruz <arnau.cruz@forgeflow.com>
- Lois Rilo <lois.rilo@forgeflow.com>

Maintainers
-----------
Expand Down
4 changes: 2 additions & 2 deletions web_excel_export_dynamic_expand/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright (C) 2024 - ForgeFlow S.L.
# Copyright 2024-26 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": "18.0.1.0.0",
"version": "18.0.1.1.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web",
"license": "AGPL-3",
Expand Down
25 changes: 15 additions & 10 deletions web_excel_export_dynamic_expand/controllers/excel_export.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 ForgeFlow S.L.
# Copyright 2024-26 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import json
Expand All @@ -25,14 +25,19 @@ def context(self):
def context(self, value):
self._context = value

def _strip_beyond_depth(self, node, current_depth, max_depth):
if current_depth >= max_depth:
aggregated_values = node.aggregated_values
node.children = OrderedDict()
node.data = []
node.aggregated_values = aggregated_values
else:
for child_node in node.children.values():
self._strip_beyond_depth(child_node, current_depth + 1, max_depth)

def from_group_data(self, fields, columns_headers, 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
expand_depth = self.context.get("expand_depth")
if expand_depth is not None:
for child_node in groups.children.values():
self._strip_beyond_depth(child_node, 0, expand_depth)
return super().from_group_data(fields, columns_headers, groups)
1 change: 1 addition & 0 deletions web_excel_export_dynamic_expand/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Arnau Cruz \<arnau.cruz@forgeflow.com\>
- Lois Rilo \<lois.rilo@forgeflow.com\>
13 changes: 10 additions & 3 deletions web_excel_export_dynamic_expand/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
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.
When exporting a list view to an Excel file, the export mirrors the
current group expansion state. The number of group levels visible in
the UI determines how many levels are included in the export:

- All groups collapsed → only top-level group summary rows.
- N levels of groups expanded → N levels of group summary rows, each
with its aggregated values but no further detail.
- All levels expanded → full export including individual records.

This works with any number of Group By filters applied simultaneously.
18 changes: 13 additions & 5 deletions web_excel_export_dynamic_expand/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Web Excel Export Dynamic Expand</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -372,12 +372,19 @@ <h1>Web Excel Export Dynamic Expand</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0ebaf3ae34e14b004119de667f5e9923e0e3cc6a0e57349fd4b860af03a2b9c2
!! source digest: sha256:ced8400976e85e06231ac225317538ade452c1b9cc5a427ad22ae7591ec2e9d1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/18.0/web_excel_export_dynamic_expand"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_excel_export_dynamic_expand"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>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.</p>
<p>When exporting a list view to an Excel file, the export mirrors the
current group expansion state. The number of group levels visible in the
UI determines how many levels are included in the export:</p>
<ul class="simple">
<li>All groups collapsed → only top-level group summary rows.</li>
<li>N levels of groups expanded → N levels of group summary rows, each
with its aggregated values but no further detail.</li>
<li>All levels expanded → full export including individual records.</li>
</ul>
<p>This works with any number of Group By filters applied simultaneously.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down Expand Up @@ -410,6 +417,7 @@ <h3><a class="toc-backref" href="#toc-entry-3">Authors</a></h3>
<h3><a class="toc-backref" href="#toc-entry-4">Contributors</a></h3>
<ul class="simple">
<li>Arnau Cruz &lt;<a class="reference external" href="mailto:arnau.cruz&#64;forgeflow.com">arnau.cruz&#64;forgeflow.com</a>&gt;</li>
<li>Lois Rilo &lt;<a class="reference external" href="mailto:lois.rilo&#64;forgeflow.com">lois.rilo&#64;forgeflow.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
33 changes: 24 additions & 9 deletions web_excel_export_dynamic_expand/static/src/js/data_export.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,30 @@ import {ListController} from "@web/views/list/list_controller";

patch(ListController.prototype, {
async downloadExport() {
const hasDataRow = document.querySelectorAll(".o_data_row").length > 0;
const hasGroup = document.querySelectorAll(".o_group_header").length > 0;
const collapseGroups = !hasDataRow && hasGroup;

this.props.context = {
...this.props.context,
collapse_groups: collapseGroups,
};

const root = this.model.root;
if (root.isGrouped && root.groups && root.groups.length > 0) {
const expandDepth = this._getExpandDepth(root);
this.props.context = {
...this.props.context,
expand_depth: expandDepth,
};
}
await super.downloadExport(...arguments);
},

_getExpandDepth(list, depth = 0) {
if (!list.isGrouped) {
return depth;
}
let maxDepth = depth;
for (const group of list.groups) {
if (!group.isFolded && group.list) {
const childDepth = this._getExpandDepth(group.list, depth + 1);
if (childDepth > maxDepth) {
maxDepth = childDepth;
}
}
}
return maxDepth;
},
});
Loading