From 5746973f456e3b109de40f86fafca77fccc99784 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Tue, 19 Oct 2021 10:50:51 +0200 Subject: [PATCH] [RFR] mis_template_financial_report: make horizontal rendering optional --- mis_template_financial_report/README.rst | 7 ++++ mis_template_financial_report/__manifest__.py | 1 + .../models/mis_report_instance.py | 26 ++++++++------ .../readme/CONFIGURE.rst | 3 ++ .../static/description/index.html | 35 +++++++++++-------- .../test_mis_template_financial_report.py | 3 ++ .../views/mis_report_instance_views.xml | 17 +++++++++ .../views/templates.xml | 4 +-- 8 files changed, 70 insertions(+), 26 deletions(-) create mode 100644 mis_template_financial_report/readme/CONFIGURE.rst create mode 100644 mis_template_financial_report/views/mis_report_instance_views.xml diff --git a/mis_template_financial_report/README.rst b/mis_template_financial_report/README.rst index 13f8fbff..0d862e99 100644 --- a/mis_template_financial_report/README.rst +++ b/mis_template_financial_report/README.rst @@ -32,6 +32,13 @@ This addon provides MIS builder templates to generate generic Profit & Loss and .. contents:: :local: +Configuration +============= + +To render the reports from this module horizontally in two columns on the same +page, check the `Horizontal` checkbox on the report template. This checkbox is +only available for reports that support the horizontal mode. + Usage ===== diff --git a/mis_template_financial_report/__manifest__.py b/mis_template_financial_report/__manifest__.py index 1ca777b1..ebb14a27 100644 --- a/mis_template_financial_report/__manifest__.py +++ b/mis_template_financial_report/__manifest__.py @@ -14,6 +14,7 @@ "data/mis_report.xml", "data/mis_report_kpi.xml", "data/mis_report_subreport.xml", + "views/mis_report_instance_views.xml", "views/templates.xml", ], "qweb": ["static/src/xml/mis_template_financial_report.xml"], diff --git a/mis_template_financial_report/models/mis_report_instance.py b/mis_template_financial_report/models/mis_report_instance.py index eb34a066..a4a268b8 100644 --- a/mis_template_financial_report/models/mis_report_instance.py +++ b/mis_template_financial_report/models/mis_report_instance.py @@ -3,14 +3,28 @@ import copy from collections import OrderedDict -from odoo import models +from odoo import api, fields, models class MisReportInstance(models.Model): _inherit = "mis.report.instance" + allow_horizontal = fields.Boolean(compute="_compute_allow_horizontal") + horizontal = fields.Boolean() + + @api.depends("report_id") + 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", + } + def compute(self): - if not self._is_horizontal(): + if not self.horizontal: return super().compute() full_matrix = self._compute_matrix() @@ -24,14 +38,6 @@ class MisReportInstance(models.Model): return result - def _is_horizontal(self): - """Determine if the report template is a horizontal one""" - self.ensure_one() - return set(self.report_id.get_external_id().values()) & { - "mis_template_financial_report.report_bs", - "mis_template_financial_report.report_pl", - } - def _compute_horizontal_matrices(self, matrix=None): """Compute the matrix (if not passed) and return the split versions""" return self._split_matrix( diff --git a/mis_template_financial_report/readme/CONFIGURE.rst b/mis_template_financial_report/readme/CONFIGURE.rst new file mode 100644 index 00000000..2a870ac3 --- /dev/null +++ b/mis_template_financial_report/readme/CONFIGURE.rst @@ -0,0 +1,3 @@ +To render the reports from this module horizontally in two columns on the same +page, check the `Horizontal` checkbox on the `Layout` tab of the report. +This checkbox is only available for reports that support the horizontal mode. diff --git a/mis_template_financial_report/static/description/index.html b/mis_template_financial_report/static/description/index.html index fe3d0540..4c422906 100644 --- a/mis_template_financial_report/static/description/index.html +++ b/mis_template_financial_report/static/description/index.html @@ -372,30 +372,37 @@ ul.auto-toc {

Table of contents

+
+

Configuration

+

To render the reports from this module horizontally in two columns on the same +page, check the Horizontal checkbox on the report template. This checkbox is +only available for reports that support the horizontal mode.

+
-

Usage

+

Usage

Select one of the Profit & Loss or Balance Sheet templates in a new MIS report.

For details, refer to the MIS Builder documentation

-

Known issues / Roadmap

+

Known issues / Roadmap

-

Bug Tracker

+

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 smashing it by providing a detailed and welcomed @@ -403,22 +410,22 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Hunki Enterprises BV
-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose 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 c6ab4892..9ae2f616 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 @@ -1,4 +1,5 @@ # Copyright 2020 Hunki Enterprises BV +# Copyright 2021 Opener B.V. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo.addons.mis_builder.tests.test_mis_report_instance import TestMisReportInstance @@ -11,5 +12,7 @@ class TestMisTemplateFinancialReport(TestMisReportInstance): "report_id": self.env.ref("mis_template_financial_report.report_bs").id, } ) + self.assertTrue(instance.allow_horizontal) + instance.horizontal = True result_dict = instance.compute() self.assertEqual(len(result_dict.get("horizontal_matrices", [])), 2) diff --git a/mis_template_financial_report/views/mis_report_instance_views.xml b/mis_template_financial_report/views/mis_report_instance_views.xml new file mode 100644 index 00000000..27f20a6c --- /dev/null +++ b/mis_template_financial_report/views/mis_report_instance_views.xml @@ -0,0 +1,17 @@ + + + + Add horizontal option to MIS report instance form + mis.report.instance + + + + + + + + + diff --git a/mis_template_financial_report/views/templates.xml b/mis_template_financial_report/views/templates.xml index 7e341591..f2b00111 100644 --- a/mis_template_financial_report/views/templates.xml +++ b/mis_template_financial_report/views/templates.xml @@ -20,7 +20,7 @@ inherit_id="mis_builder.report_mis_report_instance" > - not o._is_horizontal() + not o.horizontal @@ -35,7 +35,7 @@ -

+