Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][ADD] mis_template_financial_report_detailed #1102

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
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
89 changes: 89 additions & 0 deletions mis_template_financal_report_detailed/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
======================
Detailed PL/BS Reports
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:225f5c8b13ab9e0dd846224afd0182f4ada4df10f7ebf8872701df6d33c1927b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--reporting-lightgray.png?logo=github
:target: https://github.com/OCA/account-financial-reporting/tree/17.0/mis_template_financal_report_detailed
:alt: OCA/account-financial-reporting
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-financial-reporting-17-0/account-financial-reporting-17-0-mis_template_financal_report_detailed
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-reporting&target_branch=17.0
:alt: Try me on Runboat

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

This module will import some styles, and dynamically generate:

- (mis.report) Profit & Loss, detailed
- (mis.report) Balance Sheet, detailed
- (mis.report.instance) Profit & Loss, last 2 years
- (mis.report.instance) Balance Sheet, last 2 years

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-financial-reporting/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/account-financial-reporting/issues/new?body=module:%20mis_template_financal_report_detailed%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Ows

Contributors
------------

- Henrik Norlin

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-ows-cloud| image:: https://github.com/ows-cloud.png?size=40px
:target: https://github.com/ows-cloud
:alt: ows-cloud

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ows-cloud|

This module is part of the `OCA/account-financial-reporting <https://github.com/OCA/account-financial-reporting/tree/17.0/mis_template_financal_report_detailed>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions mis_template_financal_report_detailed/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import hooks
from . import models
21 changes: 21 additions & 0 deletions mis_template_financal_report_detailed/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2022-2024 Ows - Henrik Norlin
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Detailed PL/BS Reports",
"summary": "",
"author": "Ows, Odoo Community Association (OCA)",
"category": "Reporting",
"data": [
"data/mis_report_style.xml",
],
"demo": [],
"depends": [
"mis_builder",
],
"license": "AGPL-3",
"maintainers": ["ows-cloud"],
"post_init_hook": "post_init_hook",
"version": "17.0.1.0.0",
"website": "https://github.com/OCA/account-financial-reporting",
}
32 changes: 32 additions & 0 deletions mis_template_financal_report_detailed/data/mis_report_style.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!-- These styles are copied from mis_template_financial_report -->
<odoo>
<record id="style_default" model="mis.report.style">
<field name="name">PL/BS default</field>
<field name="dp_inherit">false</field>
<field name="dp">2</field>
<field name="hide_empty_inherit">false</field>
<field name="hide_empty">true</field>
</record>
<record id="style_header" model="mis.report.style">
<field name="name">PL/BS header</field>
<field name="font_weight_inherit">false</field>
<field name="font_weight">bold</field>
</record>
<record id="style_details_double_indent" model="mis.report.style">
<field name="name">PL/BS double indented details</field>
<field name="indent_level_inherit">false</field>
<field name="indent_level">2</field>
</record>
<record id="style_header_indent" model="mis.report.style">
<field name="name">PL/BS indented header</field>
<field name="font_weight_inherit">false</field>
<field name="font_weight">bold</field>
<field name="indent_level_inherit">false</field>
<field name="indent_level">1</field>
</record>
<record id="style_details" model="mis.report.style">
<field name="name">PL/BS details</field>
<field name="indent_level_inherit">false</field>
<field name="indent_level">1</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions mis_template_financal_report_detailed/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from odoo import SUPERUSER_ID, api


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env["mis.report"].generate_reports()
1 change: 1 addition & 0 deletions mis_template_financal_report_detailed/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import mis_report
235 changes: 235 additions & 0 deletions mis_template_financal_report_detailed/models/mis_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
# Copyright 2022-2024 Ows AS
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import re
from collections import OrderedDict

from odoo import api, models


class MisReport(models.Model):
_inherit = "mis.report"

@api.model
def generate_reports(self):
sequence = 0

""" PROFIT & LOSS (mis.report) """

report_pl = self.create(
{
"name": "Profit & Loss, detailed",
"style_id": self.env.ref(
"mis_template_financial_report_detailed.style_default"
).id,
}
)

income_kpi, sequence = self._create_account_type_kpis(
"income", report_pl, sequence
)
expense_kpi, sequence = self._create_account_type_kpis(
"expense", report_pl, sequence
)
pl_kpi, sequence = self._create_kpi_with_sequence(
{
"name": "pl",
"description": "PROFIT & LOSS",
"expression": f"{income_kpi.name} + {expense_kpi.name}",
"auto_expand_accounts": False,
"style_id": self.env.ref(
"mis_template_financial_report_detailed.style_header"
).id,
"report_id": report_pl.id,
},
sequence,
)

""" BALANCE SHEET (mis.report) """

report_bs = self.create(
{
"name": "Balance Sheet, detailed",
"style_id": self.env.ref(
"mis_template_financial_report_detailed.style_default"
).id,
}
)

asset_kpi, sequence = self._create_account_type_kpis(
"asset", report_bs, sequence
)

equity_kpi, sequence = self._create_account_type_kpis(
"equity", report_bs, sequence
)
liability_kpi, sequence = self._create_account_type_kpis(
"liability", report_bs, sequence
)
unregistered_pl_kpi, sequence = self._create_kpi_with_sequence(
{
"name": "unregistered_pl",
"description": "Unregistered Profit & Loss",
"expression": "-(asset + equity + liability)",
"auto_expand_accounts": False,
"style_id": self.env.ref(
"mis_template_financial_report_detailed.style_header"
).id,
"report_id": report_bs.id,
},
sequence,
)
equity_liability_kpi, sequence = self._create_kpi_with_sequence(
{
"name": "bal_pl",
"description": "EQUITY & LIABILITY",
"expression": "{} + {} + {}".format(
equity_kpi.name, liability_kpi.name, "unregistered_pl"
),
"auto_expand_accounts": False,
"style_id": self.env.ref(
"mis_template_financial_report_detailed.style_header"
).id,
"report_id": report_bs.id,
},
sequence,
)

""" PROFIT & LOSS (mis.report.instance) """

instance_pl = self._create_instance(
{
"name": "Profit & Loss, last 2 years",
"report_id": report_pl.id,
}
)
pl_period_last_year = self._create_instance_period(
{
"name": "Last Year",
"offset": -1,
"report_instance_id": instance_pl.id,
}
)
pl_period_2nd_last_year = self._create_instance_period(
{
"name": "2nd Last Year",
"offset": -2,
"report_instance_id": instance_pl.id,
}
)

""" BALANCE SHEET (mis.report.instance) """

instance_bs = self._create_instance(
{
"name": "Balance Sheet, last 2 years",
"report_id": report_bs.id,
}
)
bs_period_last_year = self._create_instance_period(
{
"name": "Last Year",
"offset": -1,
"report_instance_id": instance_bs.id,
}
)
bs_period_2nd_last_year = self._create_instance_period(
{
"name": "2nd Last Year",
"offset": -2,
"report_instance_id": instance_bs.id,
}
)

def _create_account_type_kpis(self, internal_group, mis_report, sequence):
kpis = []
account_types_ordered = OrderedDict()
account_types = self.env["account.account.type"].search(
[
("internal_group", "=", internal_group),
("id", "!=", self.env.ref("account.data_unaffected_earnings").id),
]
)
# Order the account types by the first account code
for account_type in account_types:
first_account = self.env["account.account"].search(
[("user_type_id", "=", account_type.id)], order="code", limit=1
)
account_types_ordered[first_account.code] = account_type
# Create KPIs
for account_type in account_types_ordered.values():
kpi, sequence = self._create_account_type_kpi(
account_type, mis_report, sequence
)
kpis.append(kpi)
# Create KPI with the total
kpi_names = [kpi.name for kpi in kpis]
expression = " + ".join(kpi_names)
total_kpi, sequence = self._create_kpi_with_sequence(
{
"name": internal_group,
"description": internal_group.upper(),
"expression": expression,
"auto_expand_accounts": False,
"style_id": self.env.ref(
"mis_template_financial_report_detailed.style_header"
).id,
"report_id": mis_report.id,
},
sequence,
)
return total_kpi, sequence

def _create_account_type_kpi(self, account_type, mis_report, sequence):
expression = "bale"
if account_type.internal_group in ("income", "expense"):
expression = "-balp"
account_type_kpi_values = {
"name": re.sub("[^0-9a-zA-Z_]+", "_", account_type.name),
"description": account_type.name,
"expression": expression + f"[('user_type_id', '=', {account_type.id})][]",
"auto_expand_accounts": True,
"auto_expand_accounts_style_id": self.env.ref(
"mis_template_financial_report_detailed.style_details"
).id,
"style_id": self.env.ref(
"mis_template_financial_report_detailed.style_header"
).id,
"report_id": mis_report.id,
}
kpi, sequence = self._create_kpi_with_sequence(
account_type_kpi_values, sequence
)
return kpi, sequence

def _create_kpi_with_sequence(self, values, sequence):
sequence += 1
kpi_values = {
"type": "num",
"compare_method": "pct",
"accumulation_method": "sum",
"sequence": sequence,
}
kpi_values.update(values)
kpi = self.env["mis.report.kpi"].create(kpi_values)
return kpi, sequence

def _create_instance(self, values):
instance_values = {
"comparison_mode": True,
"no_auto_expand_accounts": False,
"display_columns_description": True,
"target_move": "all",
}
instance_values.update(values)
return self.env["mis.report.instance"].create(instance_values)

def _create_instance_period(self, values):
period_values = {
"source": "actuals",
"mode": "relative",
"type": "y",
"duration": 1,
}
period_values.update(values)
return self.env["mis.report.instance.period"].create(period_values)
3 changes: 3 additions & 0 deletions mis_template_financal_report_detailed/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Henrik Norlin
Loading
Loading