From 1bd4f2e5497350bcac019ce605e57abf4f219658 Mon Sep 17 00:00:00 2001 From: Nicolas JEUDY Date: Fri, 20 Aug 2021 09:21:05 +0000 Subject: [PATCH] [NEW] add mis_builder_analytic_cash_flow --- mis_builder_analytic_cash_flow/README.rst | 102 ++++++++++++++++++ mis_builder_analytic_cash_flow/__init__.py | 2 + .../__manifest__.py | 21 ++++ .../models/__init__.py | 1 + .../models/mis_cash_flow_forecast_line.py | 15 +++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 5 + .../readme/ROADMAP.rst | 3 + .../readme/USAGE.rst | 4 + .../report/__init__.py | 1 + .../report/mis_cash_flow.py | 81 ++++++++++++++ .../report/mis_cash_flow_views.xml | 37 +++++++ .../mis_cash_flow_forecast_line_views.xml | 38 +++++++ 13 files changed, 311 insertions(+) create mode 100644 mis_builder_analytic_cash_flow/README.rst create mode 100644 mis_builder_analytic_cash_flow/__init__.py create mode 100644 mis_builder_analytic_cash_flow/__manifest__.py create mode 100644 mis_builder_analytic_cash_flow/models/__init__.py create mode 100644 mis_builder_analytic_cash_flow/models/mis_cash_flow_forecast_line.py create mode 100644 mis_builder_analytic_cash_flow/readme/CONTRIBUTORS.rst create mode 100644 mis_builder_analytic_cash_flow/readme/DESCRIPTION.rst create mode 100644 mis_builder_analytic_cash_flow/readme/ROADMAP.rst create mode 100644 mis_builder_analytic_cash_flow/readme/USAGE.rst create mode 100644 mis_builder_analytic_cash_flow/report/__init__.py create mode 100644 mis_builder_analytic_cash_flow/report/mis_cash_flow.py create mode 100644 mis_builder_analytic_cash_flow/report/mis_cash_flow_views.xml create mode 100644 mis_builder_analytic_cash_flow/views/mis_cash_flow_forecast_line_views.xml diff --git a/mis_builder_analytic_cash_flow/README.rst b/mis_builder_analytic_cash_flow/README.rst new file mode 100644 index 00000000..87e80f2a --- /dev/null +++ b/mis_builder_analytic_cash_flow/README.rst @@ -0,0 +1,102 @@ +===================== +MIS Builder Cash Flow +===================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-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/12.0/mis_builder_cash_flow + :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-12-0/account-financial-reporting-12-0-mis_builder_cash_flow + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/91/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to have a cash flow forecast. +The forecast is based on two types of date: + +* Accounting entries: Due date field instead of Date +* Forecast lines: manual lines created that forecast in/out cashflow moves. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Go to Accounting > Reports > MIS Reporting > MIS Reports and choose "Cash Flow" report +#. You can add forecast lines on Accounting > Reports > MIS Reporting > Cash Flow Forecast Line + +Known issues / Roadmap +====================== + +The mis_builder `roadmap `_ +and `known issues `_ can +be found on GitHub. + +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 +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ADHOC SA + +Contributors +~~~~~~~~~~~~ + +* Juan José Scarafía +* Gonzalo Ruzafa +* Alberto Martín + +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-jjscarafia| image:: https://github.com/jjscarafia.png?size=40px + :target: https://github.com/jjscarafia + :alt: jjscarafia + +Current `maintainer `__: + +|maintainer-jjscarafia| + +This module is part of the `OCA/account-financial-reporting `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mis_builder_analytic_cash_flow/__init__.py b/mis_builder_analytic_cash_flow/__init__.py new file mode 100644 index 00000000..bf588bc8 --- /dev/null +++ b/mis_builder_analytic_cash_flow/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import report diff --git a/mis_builder_analytic_cash_flow/__manifest__.py b/mis_builder_analytic_cash_flow/__manifest__.py new file mode 100644 index 00000000..8a55f4a5 --- /dev/null +++ b/mis_builder_analytic_cash_flow/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2021 Nicolas JEUDY +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'MIS Builder Analytic Cash Flow', + 'version': '12.0.1.0.0', + 'license': 'LGPL-3', + 'author': 'Nicolas JEUDY, ' + 'Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/mis-builder', + 'depends': [ + 'mis_builder_cash_flow', + ], + 'data': [ + 'report/mis_cash_flow_views.xml', + 'views/mis_cash_flow_forecast_line_views.xml', + ], + 'installable': True, + 'maintainers': ['njeudy'], + 'development_status': 'Beta', +} diff --git a/mis_builder_analytic_cash_flow/models/__init__.py b/mis_builder_analytic_cash_flow/models/__init__.py new file mode 100644 index 00000000..a917d910 --- /dev/null +++ b/mis_builder_analytic_cash_flow/models/__init__.py @@ -0,0 +1 @@ +from . import mis_cash_flow_forecast_line diff --git a/mis_builder_analytic_cash_flow/models/mis_cash_flow_forecast_line.py b/mis_builder_analytic_cash_flow/models/mis_cash_flow_forecast_line.py new file mode 100644 index 00000000..cc8ebc69 --- /dev/null +++ b/mis_builder_analytic_cash_flow/models/mis_cash_flow_forecast_line.py @@ -0,0 +1,15 @@ +from odoo import fields, models, api, _ +from odoo.exceptions import ValidationError + + +class MisCashFlowForecastLine(models.Model): + + _inherit = 'mis.cash_flow.forecast_line' + + analytic_account_id = fields.Many2one( + comodel_name='account.analytic.account', + string='Analytic Account', + required=True, + help='The account of the forecast line is only for informative ' + 'purpose', + ) diff --git a/mis_builder_analytic_cash_flow/readme/CONTRIBUTORS.rst b/mis_builder_analytic_cash_flow/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..c97a74f9 --- /dev/null +++ b/mis_builder_analytic_cash_flow/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Nicolas JEUDY diff --git a/mis_builder_analytic_cash_flow/readme/DESCRIPTION.rst b/mis_builder_analytic_cash_flow/readme/DESCRIPTION.rst new file mode 100644 index 00000000..a4f6019f --- /dev/null +++ b/mis_builder_analytic_cash_flow/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This module allows you to have a cash flow forecast with account analytic filter. +The forecast is based on two types of date: + +* Accounting entries: Due date field instead of Date +* Forecast lines: manual lines created that forecast in/out cashflow moves. diff --git a/mis_builder_analytic_cash_flow/readme/ROADMAP.rst b/mis_builder_analytic_cash_flow/readme/ROADMAP.rst new file mode 100644 index 00000000..b11c6391 --- /dev/null +++ b/mis_builder_analytic_cash_flow/readme/ROADMAP.rst @@ -0,0 +1,3 @@ +The mis_builder `roadmap `_ +and `known issues `_ can +be found on GitHub. diff --git a/mis_builder_analytic_cash_flow/readme/USAGE.rst b/mis_builder_analytic_cash_flow/readme/USAGE.rst new file mode 100644 index 00000000..44f6253a --- /dev/null +++ b/mis_builder_analytic_cash_flow/readme/USAGE.rst @@ -0,0 +1,4 @@ +To use this module, you need to: + +#. Go to Accounting > Reports > MIS Reporting > MIS Reports and choose "Cash Flow" report +#. You can add forecast lines on Accounting > Reports > MIS Reporting > Cash Flow Forecast Line diff --git a/mis_builder_analytic_cash_flow/report/__init__.py b/mis_builder_analytic_cash_flow/report/__init__.py new file mode 100644 index 00000000..00706182 --- /dev/null +++ b/mis_builder_analytic_cash_flow/report/__init__.py @@ -0,0 +1 @@ +from . import mis_cash_flow diff --git a/mis_builder_analytic_cash_flow/report/mis_cash_flow.py b/mis_builder_analytic_cash_flow/report/mis_cash_flow.py new file mode 100644 index 00000000..286dc812 --- /dev/null +++ b/mis_builder_analytic_cash_flow/report/mis_cash_flow.py @@ -0,0 +1,81 @@ +from odoo import api, fields, models, tools +from psycopg2.extensions import AsIs + + +class MisCashFlow(models.Model): + + _inherit = 'mis.cash_flow' + + + analytic_account_id = fields.Many2one( + comodel_name='account.analytic.account', + string='Analytic Account', + auto_join=True, + index=True, + readonly=True, + ) + + + @api.model_cr + def init(self): + account_type_receivable = self.env.ref( + 'account.data_account_type_receivable') + query = """ + SELECT + -- we use negative id to avoid duplicates and we don't use + -- ROW_NUMBER() because the performance was very poor + -aml.id as id, + CAST('move_line' AS varchar) as line_type, + aml.id as move_line_id, + aml.account_id as account_id, + aml.analytic_account_id as analytic_account_id, + aml.debit as debit, + aml.credit as credit, + aml.reconciled as reconciled, + aml.full_reconcile_id as full_reconcile_id, + aml.partner_id as partner_id, + aml.company_id as company_id, + aml.user_type_id as user_type_id, + aml.name as name, + aml.date_maturity as date + FROM account_move_line as aml + UNION ALL + SELECT + fl.id as id, + CAST('forecast_line' AS varchar) as line_type, + Null as move_line_id, + fl.account_id as account_id, + fl.analytic_account_id as analytic_account_id, + CASE + WHEN fl.balance > 0 + THEN fl.balance + ELSE 0.0 + END AS debit, + CASE + WHEN fl.balance < 0 + THEN -fl.balance + ELSE 0.0 + END AS credit, + Null as reconciled, + Null as full_reconcile_id, + fl.partner_id as partner_id, + fl.company_id as company_id, + %i as user_type_id, + fl.name as name, + fl.date as date + FROM mis_cash_flow_forecast_line as fl + """ % account_type_receivable.id + tools.drop_view_if_exists(self.env.cr, self._table) + self._cr.execute( + 'CREATE OR REPLACE VIEW %s AS %s', + (AsIs(self._table), AsIs(query)) + ) + + @api.multi + def action_open_related_line(self): + self.ensure_one() + if self.line_type == 'move_line': + return self.move_line_id.get_formview_action() + else: + return self.env['mis.cash_flow.forecast_line'].browse( + self.id).get_formview_action() diff --git a/mis_builder_analytic_cash_flow/report/mis_cash_flow_views.xml b/mis_builder_analytic_cash_flow/report/mis_cash_flow_views.xml new file mode 100644 index 00000000..a325c17d --- /dev/null +++ b/mis_builder_analytic_cash_flow/report/mis_cash_flow_views.xml @@ -0,0 +1,37 @@ + + + + + mis_analytic_cash_flow_tree_view + mis.cash_flow + + + + + + + + + + mis_analytic_cash_flow_form_view + mis.cash_flow + + + + + + + + + + mis_cash_flow_search_view + mis.cash_flow + + + + + + + + + diff --git a/mis_builder_analytic_cash_flow/views/mis_cash_flow_forecast_line_views.xml b/mis_builder_analytic_cash_flow/views/mis_cash_flow_forecast_line_views.xml new file mode 100644 index 00000000..8812d8e0 --- /dev/null +++ b/mis_builder_analytic_cash_flow/views/mis_cash_flow_forecast_line_views.xml @@ -0,0 +1,38 @@ + + + + + + mis_analytic_cash_flow_forecast_line_view_form + mis.cash_flow.forecast_line + + + + + + + + + + mis_analytic_cash_flow_forecast_line_view_search + mis.cash_flow.forecast_line + + + + + + + + + + mis_analitic_cash_flow_forecast_line_view_tree + mis.cash_flow.forecast_line + + + + + + + + +