From 0de1787939f943800f013a9daffba5c6b48d5106 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 + .../i18n/mis_template_financial_report.pot | 89 +++++++++++++++++++ .../models/mis_report_instance.py | 26 +++--- .../readme/CONFIGURE.rst | 3 + .../static/description/index.html | 37 ++++---- .../test_mis_template_financial_report.py | 3 + .../views/mis_report_instance_views.xml | 17 ++++ .../views/templates.xml | 4 +- 9 files changed, 160 insertions(+), 27 deletions(-) create mode 100644 mis_template_financial_report/i18n/mis_template_financial_report.pot 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..7e68b719 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 `Layout` tab of the report. +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/i18n/mis_template_financial_report.pot b/mis_template_financial_report/i18n/mis_template_financial_report.pot new file mode 100644 index 00000000..a3415389 --- /dev/null +++ b/mis_template_financial_report/i18n/mis_template_financial_report.pot @@ -0,0 +1,89 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mis_template_financial_report +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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: mis_template_financial_report +#: model:ir.model.fields,field_description:mis_template_financial_report.field_mis_report_instance__allow_horizontal +msgid "Allow Horizontal" +msgstr "" + +#. module: mis_template_financial_report +#: model:mis.report.kpi,description:mis_template_financial_report.kpi_assets +msgid "Assets" +msgstr "" + +#. module: mis_template_financial_report +#: model:mis.report,name:mis_template_financial_report.report_bs +msgid "Balance Sheet" +msgstr "" + +#. module: mis_template_financial_report +#: model:ir.model.fields,field_description:mis_template_financial_report.field_mis_report_instance__display_name +msgid "Display Name" +msgstr "" + +#. module: mis_template_financial_report +#: model:ir.model.fields,field_description:mis_template_financial_report.field_mis_report_instance__horizontal +msgid "Horizontal" +msgstr "" + +#. module: mis_template_financial_report +#: model:ir.model.fields,field_description:mis_template_financial_report.field_mis_report_instance__id +msgid "ID" +msgstr "" + +#. module: mis_template_financial_report +#: model:ir.model.fields,field_description:mis_template_financial_report.field_mis_report_instance____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mis_template_financial_report +#: model:mis.report.kpi,description:mis_template_financial_report.kpi_liability +msgid "Liabilities" +msgstr "" + +#. module: mis_template_financial_report +#: model:mis.report.kpi,description:mis_template_financial_report.kpi_liability_total +msgid "Liability" +msgstr "" + +#. module: mis_template_financial_report +#: model:mis.report.kpi,description:mis_template_financial_report.kpi_loss +msgid "Loss" +msgstr "" + +#. module: mis_template_financial_report +#: model:ir.model,name:mis_template_financial_report.model_mis_report_instance +msgid "MIS Report Instance" +msgstr "" + +#. module: mis_template_financial_report +#: model:mis.report.kpi,description:mis_template_financial_report.kpi_profit +msgid "Profit" +msgstr "" + +#. module: mis_template_financial_report +#: model:mis.report,name:mis_template_financial_report.report_pl +msgid "Profit & Loss" +msgstr "" + +#. module: mis_template_financial_report +#: model:mis.report.kpi,description:mis_template_financial_report.kpi_liability_pl_subreport +msgid "Profit / Loss" +msgstr "" + +#. module: mis_template_financial_report +#: model:mis.report.kpi,description:mis_template_financial_report.kpi_pl_to_report +msgid "Profit or loss to report" +msgstr "" 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..8ab0ef84 100644 --- a/mis_template_financial_report/static/description/index.html +++ b/mis_template_financial_report/static/description/index.html @@ -3,7 +3,7 @@ - + Profit & Loss / Balance sheet MIS templates