[RFR] mis_template_financial_report: make horizontal rendering optional

pull/1012/head
Stefan Rijnhart 2021-10-19 10:50:51 +02:00 committed by Luis Ernesto García Medina
parent c7b1633adb
commit 0de1787939
9 changed files with 160 additions and 27 deletions

View File

@ -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
=====

View File

@ -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"],

View File

@ -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 ""

View File

@ -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(

View File

@ -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.

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<title>Profit &amp; Loss / Balance sheet MIS templates</title>
<style type="text/css">
@ -372,30 +372,37 @@ ul.auto-toc {
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="id2">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="id3">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id4">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id5">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id6">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id7">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id8">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<p>To render the reports from this module horizontally in two columns on the same
page, check the <cite>Horizontal</cite> checkbox on the <cite>Layout</cite> tab of the report.
This checkbox is only available for reports that support the horizontal mode.</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
<p>Select one of the <cite>Profit &amp; Loss</cite> or <cite>Balance Sheet</cite> templates in a new MIS report.</p>
<p>For details, refer to the <a class="reference external" href="https://github.com/OCA/mis-builder/tree/14.0/mis_builder#usage">MIS Builder documentation</a></p>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#id2">Known issues / Roadmap</a></h1>
<h1><a class="toc-backref" href="#id3">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>support horizontal mode for xslx export</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-financial-reporting/issues">GitHub Issues</a>.
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
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
<h1><a class="toc-backref" href="#id5">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
<h2><a class="toc-backref" href="#id6">Authors</a></h2>
<ul class="simple">
<li>Hunki Enterprises BV</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<h2><a class="toc-backref" href="#id7">Contributors</a></h2>
<ul class="simple">
<li>Holger Brunn &lt;<a class="reference external" href="mailto:mail&#64;hunki-enterprises.nl">mail&#64;hunki-enterprises.nl</a>&gt; (<a class="reference external" href="https://hunki-enterprises.nl">https://hunki-enterprises.nl</a>)</li>
<li>Stefan Rijnhart &lt;<a class="reference external" href="mailto:stefan&#64;opener.amsterdam">stefan&#64;opener.amsterdam</a>&gt; (<a class="reference external" href="https://opener.amsterdam">https://opener.amsterdam</a>)</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose

View File

@ -1,4 +1,5 @@
# Copyright 2020 Hunki Enterprises BV
# Copyright 2021 Opener B.V. <stefan@opener.am>
# 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)

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record model="ir.ui.view" id="mis_report_instance_view_form">
<field name="name">Add horizontal option to MIS report instance form</field>
<field name="model">mis.report.instance</field>
<field name="inherit_id" ref="mis_builder.mis_report_instance_view_form" />
<field name="arch" type="xml">
<group name="layout" position="inside">
<field name="allow_horizontal" invisible="1" />
<field
name="horizontal"
attrs="{'invisible': [('allow_horizontal', '=', False)]}"
/>
</group>
</field>
</record>
</odoo>

View File

@ -20,7 +20,7 @@
inherit_id="mis_builder.report_mis_report_instance"
>
<xpath expr="//div[hasclass('mis_table')]" position="attributes">
<attribute name="t-if">not o._is_horizontal()</attribute>
<attribute name="t-if">not o.horizontal</attribute>
</xpath>
<!-- the following is a somewhat convoluted way to duplicate the table /-->
<xpath expr="//div[hasclass('mis_table')]" position="replace">
@ -35,7 +35,7 @@
</xpath>
<xpath expr="//t[@t-marker='unwrap']" position="replace" />
<xpath expr="//t[@t-marker='wrap_in_table']" position="after">
<div t-if="o._is_horizontal()" class="mis_builder_horizontal">
<div t-if="o.horizontal" class="mis_builder_horizontal">
<div>
<div t-foreach="o._compute_horizontal_matrices()" t-as="matrix" />
</div>