diff --git a/account_move_line_cumulated_balance/README.rst b/account_move_line_cumulated_balance/README.rst new file mode 100644 index 000000000..fcd83be3c --- /dev/null +++ b/account_move_line_cumulated_balance/README.rst @@ -0,0 +1,106 @@ +================================ +Journal Ledger Cumulated Balance +================================ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-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--tools-lightgray.png?logo=github + :target: https://github.com/OCA/account-financial-tools/tree/13.0/account_move_line_cumulated_balance + :alt: OCA/account-financial-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-financial-tools-13-0/account-financial-tools-13-0-account_move_line_cumulated_balance + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/92/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to show the cumulated balance, both in the company +currency and in the original currency, on the general ledger and partner ledger +menus, which is an aid for accountants that need to check the evolution of the +balances. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To see all the menus, make sure: + +* Your user is member of the group + "Technical Settings / Show Full Accounting Features" +* The page is running in debug mode or you have the `base_technical_features` + module installed and belonging to such group. + +Usage +===== + +#. Go to *Invoicing > Accounting > General Ledger* or + *Invoicing > Accounting > Partner Ledger* +#. Two new columns will be available: + + * Cumulated Balance + * Cumulated Balance in Currency + +Known issues / Roadmap +====================== + +* For v14, there's only need to migrate the field amount_currency_balance, as + the other one already exists in core. + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* Odoo SA +* `Tecnativa `_: + + * César A. Sánchez + * Pedro M. Baeza + +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. + +This module is part of the `OCA/account-financial-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_move_line_cumulated_balance/__init__.py b/account_move_line_cumulated_balance/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_move_line_cumulated_balance/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_move_line_cumulated_balance/__manifest__.py b/account_move_line_cumulated_balance/__manifest__.py new file mode 100644 index 000000000..14bee2589 --- /dev/null +++ b/account_move_line_cumulated_balance/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2022 Tecnativa - César A. Sánchez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Journal Ledger Cumulated Balance", + "summary": "Show cumulated balances on the interactive journal ledgers", + "version": "13.0.1.0.0", + "category": "Account", + "license": "AGPL-3", + "website": "https://github.com/OCA/account-financial-tools", + "author": "Tecnativa, Odoo Community Association (OCA)", + "depends": ["account"], + "data": ["views/account_move_views.xml"], +} diff --git a/account_move_line_cumulated_balance/i18n/account_move_line_cumulated_balance.pot b/account_move_line_cumulated_balance/i18n/account_move_line_cumulated_balance.pot new file mode 100644 index 000000000..4aaf368dd --- /dev/null +++ b/account_move_line_cumulated_balance/i18n/account_move_line_cumulated_balance.pot @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_line_cumulated_balance +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-07-09 14:47+0000\n" +"PO-Revision-Date: 2022-07-09 14:47+0000\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: account_move_line_cumulated_balance +#: model:ir.model.fields,field_description:account_move_line_cumulated_balance.field_account_move_line__cumulated_balance +msgid "Cumulated Balance" +msgstr "" + +#. module: account_move_line_cumulated_balance +#: model:ir.model.fields,field_description:account_move_line_cumulated_balance.field_account_move_line__cumulated_balance_currency +msgid "Cumulated Balance in Currency" +msgstr "" + +#. module: account_move_line_cumulated_balance +#: model:ir.model.fields,help:account_move_line_cumulated_balance.field_account_move_line__cumulated_balance +msgid "" +"Cumulated balance depending on the domain and the order chosen in the view." +msgstr "" + +#. module: account_move_line_cumulated_balance +#: model:ir.model.fields,help:account_move_line_cumulated_balance.field_account_move_line__cumulated_balance_currency +msgid "" +"Cumulated balance in currency depending on the domain and the order chosen " +"in the view." +msgstr "" + +#. module: account_move_line_cumulated_balance +#: model:ir.model,name:account_move_line_cumulated_balance.model_account_move_line +msgid "Journal Item" +msgstr "" diff --git a/account_move_line_cumulated_balance/i18n/es.po b/account_move_line_cumulated_balance/i18n/es.po new file mode 100644 index 000000000..1457f6efd --- /dev/null +++ b/account_move_line_cumulated_balance/i18n/es.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_line_cumulated_balance +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-07-09 14:48+0000\n" +"PO-Revision-Date: 2022-07-09 16:49+0200\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"Language: es\n" +"X-Generator: Poedit 2.3\n" + +#. module: account_move_line_cumulated_balance +#: model:ir.model.fields,field_description:account_move_line_cumulated_balance.field_account_move_line__cumulated_balance +msgid "Cumulated Balance" +msgstr "Saldo acumulado" + +#. module: account_move_line_cumulated_balance +#: model:ir.model.fields,field_description:account_move_line_cumulated_balance.field_account_move_line__cumulated_balance_currency +msgid "Cumulated Balance in Currency" +msgstr "Saldo acumulado en moneda" + +#. module: account_move_line_cumulated_balance +#: model:ir.model.fields,help:account_move_line_cumulated_balance.field_account_move_line__cumulated_balance +msgid "" +"Cumulated balance depending on the domain and the order chosen in the view." +msgstr "" +"Saldo acumulado dependiendo del dominio y el orden escogidos en la vista." + +#. module: account_move_line_cumulated_balance +#: model:ir.model.fields,help:account_move_line_cumulated_balance.field_account_move_line__cumulated_balance_currency +msgid "" +"Cumulated balance in currency depending on the domain and the order chosen " +"in the view." +msgstr "" +"Saldo acumulado en moneda dependiendo del dominio y el orden escogidos en " +"la vista." + +#. module: account_move_line_cumulated_balance +#: model:ir.model,name:account_move_line_cumulated_balance.model_account_move_line +msgid "Journal Item" +msgstr "Apunte contable" diff --git a/account_move_line_cumulated_balance/models/__init__.py b/account_move_line_cumulated_balance/models/__init__.py new file mode 100644 index 000000000..8795b3bea --- /dev/null +++ b/account_move_line_cumulated_balance/models/__init__.py @@ -0,0 +1 @@ +from . import account_move_line diff --git a/account_move_line_cumulated_balance/models/account_move_line.py b/account_move_line_cumulated_balance/models/account_move_line.py new file mode 100644 index 000000000..636d11e2d --- /dev/null +++ b/account_move_line_cumulated_balance/models/account_move_line.py @@ -0,0 +1,73 @@ +# Copyright 2022 Tecnativa - César A. Sánchez +# Copyright 2022 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from psycopg2 import sql + +from odoo import api, fields, models + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + cumulated_balance = fields.Monetary( + string="Cumulated Balance", + store=False, + currency_field="company_currency_id", + compute="_compute_cumulated_balance", + help="Cumulated balance depending on the domain and the order chosen in the view.", + ) + cumulated_balance_currency = fields.Monetary( + string="Cumulated Balance in Currency", + store=False, + currency_field="currency_id", + compute="_compute_cumulated_balance", + help="Cumulated balance in currency depending on the domain and " + "the order chosen in the view.", + ) + + @api.model + def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None): + def to_tuple(t): + return tuple(map(to_tuple, t)) if isinstance(t, (list, tuple)) else t + + # Add the domain and order by in order to compute the cumulated + # balance in _compute_cumulated_balance + order = (order or self._order) + ", id desc" + return super( + AccountMoveLine, self.with_context(order_cumulated_balance=order,), + ).search_read(domain, fields, offset, limit, order) + + @api.depends_context("order_cumulated_balance") + def _compute_cumulated_balance(self): + self.cumulated_balance = 0 + self.cumulated_balance_currency = 0 + order_cumulated_balance = ( + self.env.context.get("order_cumulated_balance", self._order) + ", id" + ) + order_string = ", ".join( + self._generate_order_by_inner( + self._table, order_cumulated_balance, "", reverse_direction=False, + ) + ) + query = sql.SQL( + """SELECT account_move_line.id, + SUM(account_move_line.balance) OVER ( + ORDER BY {order_by_clause} + ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW + ), + SUM(account_move_line.amount_currency) OVER ( + ORDER BY {order_by_clause} + ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW + ) + FROM account_move_line + LEFT JOIN account_move on account_move_line.move_id = account_move.id + WHERE + account_move.state = 'posted' + """ + ).format(order_by_clause=sql.SQL(order_string),) + self.env.cr.execute(query) + result = {r[0]: (r[1], r[2]) for r in self.env.cr.fetchall()} + for record in self: + record.cumulated_balance = result[record.id][0] + record.cumulated_balance_currency = result[record.id][1] diff --git a/account_move_line_cumulated_balance/readme/CONFIGURE.rst b/account_move_line_cumulated_balance/readme/CONFIGURE.rst new file mode 100644 index 000000000..46fe02848 --- /dev/null +++ b/account_move_line_cumulated_balance/readme/CONFIGURE.rst @@ -0,0 +1,6 @@ +To see all the menus, make sure: + +* Your user is member of the group + "Technical Settings / Show Full Accounting Features" +* The page is running in debug mode or you have the `base_technical_features` + module installed and belonging to such group. diff --git a/account_move_line_cumulated_balance/readme/CONTRIBUTORS.rst b/account_move_line_cumulated_balance/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..1f53da1d1 --- /dev/null +++ b/account_move_line_cumulated_balance/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* Odoo SA +* `Tecnativa `_: + + * César A. Sánchez + * Pedro M. Baeza diff --git a/account_move_line_cumulated_balance/readme/DESCRIPTION.rst b/account_move_line_cumulated_balance/readme/DESCRIPTION.rst new file mode 100644 index 000000000..11ad8580f --- /dev/null +++ b/account_move_line_cumulated_balance/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module allows you to show the cumulated balance, both in the company +currency and in the original currency, on the general ledger and partner ledger +menus, which is an aid for accountants that need to check the evolution of the +balances. diff --git a/account_move_line_cumulated_balance/readme/ROADMAP.rst b/account_move_line_cumulated_balance/readme/ROADMAP.rst new file mode 100644 index 000000000..9df7956b3 --- /dev/null +++ b/account_move_line_cumulated_balance/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +* For v14, there's only need to migrate the field amount_currency_balance, as + the other one already exists in core. diff --git a/account_move_line_cumulated_balance/readme/USAGE.rst b/account_move_line_cumulated_balance/readme/USAGE.rst new file mode 100644 index 000000000..412b67d96 --- /dev/null +++ b/account_move_line_cumulated_balance/readme/USAGE.rst @@ -0,0 +1,6 @@ +#. Go to *Invoicing > Accounting > General Ledger* or + *Invoicing > Accounting > Partner Ledger* +#. Two new columns will be available: + + * Cumulated Balance + * Cumulated Balance in Currency diff --git a/account_move_line_cumulated_balance/static/description/icon.png b/account_move_line_cumulated_balance/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_move_line_cumulated_balance/static/description/icon.png differ diff --git a/account_move_line_cumulated_balance/static/description/index.html b/account_move_line_cumulated_balance/static/description/index.html new file mode 100644 index 000000000..89c249953 --- /dev/null +++ b/account_move_line_cumulated_balance/static/description/index.html @@ -0,0 +1,459 @@ + + + + + + +Journal Ledger Cumulated Balance + + + +
+

Journal Ledger Cumulated Balance

+ + +

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runbot

+

This module allows you to show the cumulated balance, both in the company +currency and in the original currency, on the general ledger and partner ledger +menus, which is an aid for accountants that need to check the evolution of the +balances.

+

Table of contents

+ +
+

Configuration

+

To see all the menus, make sure:

+
    +
  • Your user is member of the group +“Technical Settings / Show Full Accounting Features”
  • +
  • The page is running in debug mode or you have the base_technical_features +module installed and belonging to such group.
  • +
+
+
+

Usage

+
    +
  1. Go to Invoicing > Accounting > General Ledger or +Invoicing > Accounting > Partner Ledger
  2. +
  3. Two new columns will be available:
      +
    • Cumulated Balance
    • +
    • Cumulated Balance in Currency
    • +
    +
  4. +
+
+
+

Known issues / Roadmap

+
    +
  • For v14, there’s only need to migrate the field amount_currency_balance, as +the other one already exists in core.
  • +
+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Odoo SA
  • +
  • Tecnativa:
      +
    • César A. Sánchez
    • +
    • Pedro M. Baeza
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/account-financial-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_move_line_cumulated_balance/tests/__init__.py b/account_move_line_cumulated_balance/tests/__init__.py new file mode 100644 index 000000000..6d7bfd5fe --- /dev/null +++ b/account_move_line_cumulated_balance/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from . import test_account_move_line_cumulated_balance diff --git a/account_move_line_cumulated_balance/tests/test_account_move_line_cumulated_balance.py b/account_move_line_cumulated_balance/tests/test_account_move_line_cumulated_balance.py new file mode 100644 index 000000000..a8fd9c71c --- /dev/null +++ b/account_move_line_cumulated_balance/tests/test_account_move_line_cumulated_balance.py @@ -0,0 +1,84 @@ +# Copyright 2020 Tecnativa - Víctor Martínez +# License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html + +from odoo.tests import Form +from odoo.tests.common import SavepointCase + + +class TestAccount(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.account_account_type_model = cls.env["account.account.type"] + cls.account_account_model = cls.env["account.account"] + cls.account_type_receivable = cls.account_account_type_model.create( + {"name": "Test Receivable", "type": "receivable", "internal_group": "asset"} + ) + cls.account_type_regular = cls.account_account_type_model.create( + {"name": "Test Regular", "type": "other", "internal_group": "income"} + ) + + cls.account_receivable = cls.account_account_model.create( + { + "name": "Test Receivable", + "code": "TEST_AR", + "user_type_id": cls.account_type_receivable.id, + "reconcile": True, + } + ) + cls.account_income = cls.account_account_model.create( + { + "name": "Test Income", + "code": "TEST_IN", + "user_type_id": cls.account_type_regular.id, + "reconcile": False, + } + ) + cls.partner = cls.env["res.partner"].create( + { + "name": "Test customer", + "customer_rank": 1, + "property_account_receivable_id": cls.account_receivable.id, + } + ) + cls.journal = cls.env["account.journal"].create( + { + "name": "Test journal", + "type": "sale", + "code": "test-sale-jorunal", + "company_id": cls.env.company.id, + } + ) + cls.product = cls.env["product.product"].create( + {"name": "Test product", "type": "service"} + ) + invoice = Form( + cls.env["account.move"].with_context( + default_type="out_invoice", default_company_id=cls.env.company.id + ) + ) + invoice.partner_id = cls.partner + invoice.journal_id = cls.journal + with invoice.invoice_line_ids.new() as line_form: + line_form.name = cls.product.name + line_form.product_id = cls.product + line_form.quantity = 1.0 + line_form.price_unit = 10 + line_form.account_id = cls.account_income + invoice = invoice.save() + invoice.action_post() + cls.invoice = invoice + + def test_remove_invoice_error(self): + # Delete invoice while name isn't / + lines = ( + self.env["account.move.line"] + .with_context(order_cumulated_balance="date desc, id desc") + .search( + [("move_id.state", "=", "posted"), ("move_id", "=", self.invoice.id)] + ) + ) + self.assertAlmostEqual(lines[0].cumulated_balance, 0) + self.assertAlmostEqual(lines[0].cumulated_balance_currency, 0) + self.assertAlmostEqual(lines[1].cumulated_balance, 10) + self.assertAlmostEqual(lines[1].cumulated_balance_currency, 0) diff --git a/account_move_line_cumulated_balance/views/account_move_views.xml b/account_move_line_cumulated_balance/views/account_move_views.xml new file mode 100644 index 000000000..2bbf6cf6d --- /dev/null +++ b/account_move_line_cumulated_balance/views/account_move_views.xml @@ -0,0 +1,43 @@ + + + + account.move.line.tree.grouped.misc + account.move.line + + + + date asc + + + + + + + + + + + + account.move.line.tree.grouped.partner + account.move.line + + + + date asc + + + + + + + + + + diff --git a/setup/account_move_line_cumulated_balance/odoo/addons/account_move_line_cumulated_balance b/setup/account_move_line_cumulated_balance/odoo/addons/account_move_line_cumulated_balance new file mode 120000 index 000000000..2bd583b07 --- /dev/null +++ b/setup/account_move_line_cumulated_balance/odoo/addons/account_move_line_cumulated_balance @@ -0,0 +1 @@ +../../../../account_move_line_cumulated_balance \ No newline at end of file diff --git a/setup/account_move_line_cumulated_balance/setup.py b/setup/account_move_line_cumulated_balance/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_move_line_cumulated_balance/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)