diff --git a/mis_template_financial_report/README.rst b/mis_template_financial_report/README.rst
index 9f2ae058..502ea8a7 100644
--- a/mis_template_financial_report/README.rst
+++ b/mis_template_financial_report/README.rst
@@ -7,7 +7,7 @@ Profit & Loss / Balance sheet MIS templates
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !! source digest: sha256:ced5b0160af86207e009f52aac7844010df11f150873af1601845c0f0958ec23
+ !! source digest: sha256:35e3ad836c47238b09fe511febcb806bafddc4699aedb0e224e55517c31128d0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -53,6 +53,7 @@ Known issues / Roadmap
======================
* support horizontal mode for xslx export
+* split off all code to `mis_builder_horizontal` and only keep the KPI definitions here
Bug Tracker
===========
diff --git a/mis_template_financial_report/__manifest__.py b/mis_template_financial_report/__manifest__.py
index e8c05412..b333d290 100644
--- a/mis_template_financial_report/__manifest__.py
+++ b/mis_template_financial_report/__manifest__.py
@@ -15,16 +15,17 @@
"data/mis_report_kpi.xml",
"data/mis_report_subreport.xml",
"views/mis_report_instance_views.xml",
+ "views/mis_report_kpi_views.xml",
"views/templates.xml",
],
"assets": {
"web.assets_backend": [
- "mis_template_financial_report/static/src/css/mis_template_financial_report.css",
+ "mis_template_financial_report/static/src/components/mis_report_widget.xml",
+ "mis_template_financial_report/static/src/components/mis_report_widget.css",
],
"web.report_assets_common": [
"mis_template_financial_report/static/src/css/report.css"
],
},
- "qweb": ["static/src/xml/mis_template_financial_report.xml"],
"maintainers": ["hbrunn"],
}
diff --git a/mis_template_financial_report/data/mis_report_kpi.xml b/mis_template_financial_report/data/mis_report_kpi.xml
index 73fe1363..e25a5734 100644
--- a/mis_template_financial_report/data/mis_report_kpi.xml
+++ b/mis_template_financial_report/data/mis_report_kpi.xml
@@ -24,6 +24,7 @@
sum
0
+
3
@@ -93,5 +94,6 @@
sum
0
+
diff --git a/mis_template_financial_report/models/__init__.py b/mis_template_financial_report/models/__init__.py
index 5f14fa3b..6aa7620d 100644
--- a/mis_template_financial_report/models/__init__.py
+++ b/mis_template_financial_report/models/__init__.py
@@ -1 +1,2 @@
from . import mis_report_instance
+from . import mis_report_kpi
diff --git a/mis_template_financial_report/models/mis_report_instance.py b/mis_template_financial_report/models/mis_report_instance.py
index a4a268b8..a688b379 100644
--- a/mis_template_financial_report/models/mis_report_instance.py
+++ b/mis_template_financial_report/models/mis_report_instance.py
@@ -16,12 +16,9 @@ class MisReportInstance(models.Model):
def _compute_allow_horizontal(self):
"""Indicate that the instance supports horizontal rendering."""
for instance in self:
- instance.allow_horizontal = set(
- instance.report_id.get_external_id().values()
- ) & {
- "mis_template_financial_report.report_bs",
- "mis_template_financial_report.report_pl",
- }
+ instance.allow_horizontal = any(
+ instance.mapped("report_id.kpi_ids.split_after")
+ )
def compute(self):
if not self.horizontal:
@@ -29,55 +26,28 @@ class MisReportInstance(models.Model):
full_matrix = self._compute_matrix()
- matrices = self._compute_horizontal_matrices(full_matrix)
+ matrices = self._split_matrix(full_matrix)
result = full_matrix.as_dict()
- result["horizontal_matrices"] = [
- extra_matrix.as_dict() for extra_matrix in matrices
- ]
+ result["split_matrices"] = [extra_matrix.as_dict() for extra_matrix in matrices]
return result
- def _compute_horizontal_matrices(self, matrix=None):
- """Compute the matrix (if not passed) and return the split versions"""
- return self._split_matrix(
- matrix or self._compute_matrix(),
- [
- (
- self.env.ref("mis_template_financial_report.kpi_profit"),
- self.env.ref("mis_template_financial_report.kpi_pl_to_report"),
- self.env.ref("mis_template_financial_report.kpi_assets"),
- )
- ],
- )
-
- def _split_matrix(self, original_matrix, kpi_defs=None, keep_remaining=True):
- """Split a matrix by duplicating it as shallowly as possible and removing
- rows according to kpi_defs
-
- KPIs not listed there will end up together in the last matrix if
- `keep_remaining` is set.
-
- :param kpi_defs: [(kpi_first_matrix1, ...), (kpi_second_matrix1, ...)]
- :return: list of KpiMatrix
- """
+ def _split_matrix(self, original_matrix):
+ """Split a matrix according to the split_after flag in the kpis used"""
result = []
- remaining_rows = original_matrix._kpi_rows.copy()
- for kpis in kpi_defs:
- matrix = copy.copy(original_matrix)
- matrix._kpi_rows = OrderedDict(
- [
- (kpi, remaining_rows.pop(kpi))
- for kpi in kpis
- if kpi in remaining_rows
- ]
- )
- result.append(matrix)
+ def clone_matrix():
+ clone = copy.copy(original_matrix)
+ clone._kpi_rows = OrderedDict()
+ result.append(clone)
+ return clone
- if remaining_rows and keep_remaining:
- matrix = copy.copy(original_matrix)
- matrix._kpi_rows = remaining_rows
- result.append(matrix)
+ current = clone_matrix()
+
+ for kpi in original_matrix._kpi_rows:
+ current._kpi_rows[kpi] = original_matrix._kpi_rows[kpi]
+ if kpi.split_after:
+ current = clone_matrix()
return result
diff --git a/mis_template_financial_report/models/mis_report_kpi.py b/mis_template_financial_report/models/mis_report_kpi.py
new file mode 100644
index 00000000..fcc46639
--- /dev/null
+++ b/mis_template_financial_report/models/mis_report_kpi.py
@@ -0,0 +1,12 @@
+# Copyright 2023 Hunki Enterprises BV
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+from odoo import fields, models
+
+
+class MisReportKpi(models.Model):
+ _inherit = "mis.report.kpi"
+
+ split_after = fields.Boolean(
+ help="Split the table after this KPI. This allows displaying KPIs next to each "
+ "other in non-comparison mode",
+ )
diff --git a/mis_template_financial_report/readme/ROADMAP.rst b/mis_template_financial_report/readme/ROADMAP.rst
index d5786edd..5b5b68de 100644
--- a/mis_template_financial_report/readme/ROADMAP.rst
+++ b/mis_template_financial_report/readme/ROADMAP.rst
@@ -1 +1,2 @@
* support horizontal mode for xslx export
+* split off all code to `mis_builder_horizontal` and only keep the KPI definitions here
diff --git a/mis_template_financial_report/static/description/index.html b/mis_template_financial_report/static/description/index.html
index ae7895ea..b83951b6 100644
--- a/mis_template_financial_report/static/description/index.html
+++ b/mis_template_financial_report/static/description/index.html
@@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! source digest: sha256:ced5b0160af86207e009f52aac7844010df11f150873af1601845c0f0958ec23
+!! source digest: sha256:35e3ad836c47238b09fe511febcb806bafddc4699aedb0e224e55517c31128d0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

This addon provides MIS builder templates to generate generic Profit & Loss and Balance Sheet reports.
@@ -401,6 +401,7 @@ This checkbox is only available for reports that support the horizontal mode.Known issues / Roadmap
- support horizontal mode for xslx export
+- split off all code to mis_builder_horizontal and only keep the KPI definitions here
diff --git a/mis_template_financial_report/static/src/components/mis_report_widget.css b/mis_template_financial_report/static/src/components/mis_report_widget.css
new file mode 100644
index 00000000..39b34a55
--- /dev/null
+++ b/mis_template_financial_report/static/src/components/mis_report_widget.css
@@ -0,0 +1,11 @@
+.oe_mis_builder_content.horizontal {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 5px;
+}
+.oe_mis_builder_content.horizontal .oe_mis_builder_cp {
+ width: 100%;
+}
+.oe_mis_builder_content.horizontal .o_list_renderer {
+ flex-grow: 1;
+}
diff --git a/mis_template_financial_report/static/src/components/mis_report_widget.xml b/mis_template_financial_report/static/src/components/mis_report_widget.xml
new file mode 100644
index 00000000..7a0f9ed2
--- /dev/null
+++ b/mis_template_financial_report/static/src/components/mis_report_widget.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+ {{state.mis_report_data.split_matrices and 'horizontal'}}
+
+
+ state.mis_report_data.split_matrices or [state.mis_report_data]
+ matrix
+ matrix_index
+
+
+
+ matrix.header
+
+
+ matrix.body
+
+
+
diff --git a/mis_template_financial_report/static/src/css/mis_template_financial_report.css b/mis_template_financial_report/static/src/css/mis_template_financial_report.css
deleted file mode 100644
index 158cfb01..00000000
--- a/mis_template_financial_report/static/src/css/mis_template_financial_report.css
+++ /dev/null
@@ -1,7 +0,0 @@
-.oe_mis_builder_content div.mis_builder_horizontal {
- display: flex;
- width: 100%;
-}
-.oe_mis_builder_content div.mis_builder_horizontal .table {
- width: 50%;
-}
diff --git a/mis_template_financial_report/static/src/css/report.css b/mis_template_financial_report/static/src/css/report.css
index 376d0ed2..ee8f94b9 100644
--- a/mis_template_financial_report/static/src/css/report.css
+++ b/mis_template_financial_report/static/src/css/report.css
@@ -1,11 +1,11 @@
-div.mis_builder_horizontal {
+div.mis_builder_horizontal_container {
display: table;
width: 100%;
+ border-spacing: 5px;
}
-div.mis_builder_horizontal > div {
+div.mis_builder_horizontal_row {
display: table-row;
}
-div.mis_builder_horizontal > div > div {
+div.mis_builder_horizontal_cell {
display: table-cell;
- padding: 2px;
}
diff --git a/mis_template_financial_report/static/src/xml/mis_template_financial_report.xml b/mis_template_financial_report/static/src/xml/mis_template_financial_report.xml
deleted file mode 100644
index 31fb0f5c..00000000
--- a/mis_template_financial_report/static/src/xml/mis_template_financial_report.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
- var $full_table = jQuery(this);
- var $wrapper = jQuery(
- ''
- ).addClass('mis_builder_horizontal').insertAfter($full_table);
- var $table = $full_table.clone().appendTo($wrapper);
- $table.attr({
- 't-foreach': 'widget.mis_report_data.horizontal_matrices || []',
- 't-as': 'matrix',
- });
- $table.find('tr[t-foreach="widget.mis_report_data.header"]').attr(
- 't-foreach', 'matrix.header'
- );
- $table.find('tr[t-foreach="widget.mis_report_data.body"]').attr(
- 't-foreach', 'matrix.body'
- );
- $full_table.attr('t-if', '!widget.mis_report_data.horizontal_matrices');
-
-
-
diff --git a/mis_template_financial_report/tests/test_mis_template_financial_report.py b/mis_template_financial_report/tests/test_mis_template_financial_report.py
index 9ae2f616..2b331fb1 100644
--- a/mis_template_financial_report/tests/test_mis_template_financial_report.py
+++ b/mis_template_financial_report/tests/test_mis_template_financial_report.py
@@ -15,4 +15,4 @@ class TestMisTemplateFinancialReport(TestMisReportInstance):
self.assertTrue(instance.allow_horizontal)
instance.horizontal = True
result_dict = instance.compute()
- self.assertEqual(len(result_dict.get("horizontal_matrices", [])), 2)
+ self.assertEqual(len(result_dict.get("split_matrices", [])), 2)
diff --git a/mis_template_financial_report/views/mis_report_kpi_views.xml b/mis_template_financial_report/views/mis_report_kpi_views.xml
new file mode 100644
index 00000000..6b85ae06
--- /dev/null
+++ b/mis_template_financial_report/views/mis_report_kpi_views.xml
@@ -0,0 +1,14 @@
+
+
+
+ mis.report.kpi
+
+
+
+
+
+
+
+
+
+
diff --git a/mis_template_financial_report/views/templates.xml b/mis_template_financial_report/views/templates.xml
index 63cea76e..0e83276a 100644
--- a/mis_template_financial_report/views/templates.xml
+++ b/mis_template_financial_report/views/templates.xml
@@ -2,42 +2,25 @@
-
- not o.horizontal
-
-
-
- $0
- $0
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
-
-
-
+
+ mis_table {{o.horizontal and 'horizontal'}}