diff --git a/account_move_total_by_account_internal_group/README.rst b/account_move_total_by_account_internal_group/README.rst new file mode 100644 index 000000000..2ce2d66a5 --- /dev/null +++ b/account_move_total_by_account_internal_group/README.rst @@ -0,0 +1,85 @@ +============================================ +Account Move Total By Account Internal Group +============================================ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/15.0/account_move_total_by_account_internal_group + :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-15-0/account-financial-tools-15-0-account_move_total_by_account_internal_group + :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/15.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Displays the total balance by account internal group in the journal entries. This could +be necesssary in some context. For example, when looking at the stock journal entries +we would like to see the total assets, as long as we would like to see the assets +increasing when there is a debit in the inventory account and deceasing when the +inventory is decreased. The standard field amount_total_signed does not serve, as +it shows this as a positive value in this case. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +New hidden columns in journal Entries tree view. + +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 +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* `ForgeFlow `: + + * Aaron Henriquez + +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_total_by_account_internal_group/__init__.py b/account_move_total_by_account_internal_group/__init__.py new file mode 100644 index 000000000..6d58305f5 --- /dev/null +++ b/account_move_total_by_account_internal_group/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import pre_init_hook diff --git a/account_move_total_by_account_internal_group/__manifest__.py b/account_move_total_by_account_internal_group/__manifest__.py new file mode 100644 index 000000000..7dea2fa05 --- /dev/null +++ b/account_move_total_by_account_internal_group/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Account Move Total By Account Internal Group", + "version": "15.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "summary": "Adds Totals by Account Internal Group in Journal Entries", + "website": "https://github.com/OCA/account-financial-tools", + "license": "AGPL-3", + "depends": ["account"], + "category": "Accounting", + "data": [ + "views/account_move_views.xml", + ], + "installable": True, + "maintainer": "AaronHForgeFlow", + "development_status": "Beta", + "pre_init_hook": "pre_init_hook", +} diff --git a/account_move_total_by_account_internal_group/hooks.py b/account_move_total_by_account_internal_group/hooks.py new file mode 100644 index 000000000..a2207d882 --- /dev/null +++ b/account_move_total_by_account_internal_group/hooks.py @@ -0,0 +1,26 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import logging + + +def pre_init_hook(cr): + """Precreate account_internal_group and fill with appropriate values to prevent + a MemoryError when the ORM attempts to call its compute method on a large + amount of preexisting moves.""" + logger = logging.getLogger(__name__) + logger.info( + "Add account_move_line.account_internal_group column if it does not yet exist" + ) + cr.execute( + "ALTER TABLE account_move_line ADD COLUMN IF NOT EXISTS account_internal_group VARCHAR" + ) + cr.execute( + """ UPDATE account_move_line aml0 SET account_internal_group = aa.internal_group + FROM account_move_line aml + INNER JOIN account_account aa ON aa.id = aml.account_id + WHERE aml.id = aml0.id + AND aml.account_internal_group IS NULL + """ + ) + logger.info("Finished adding account_move_line.account_internal_group column") diff --git a/account_move_total_by_account_internal_group/models/__init__.py b/account_move_total_by_account_internal_group/models/__init__.py new file mode 100644 index 000000000..0d5ab6a2f --- /dev/null +++ b/account_move_total_by_account_internal_group/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_move +from . import account_move_line diff --git a/account_move_total_by_account_internal_group/models/account_move.py b/account_move_total_by_account_internal_group/models/account_move.py new file mode 100644 index 000000000..516c337e8 --- /dev/null +++ b/account_move_total_by_account_internal_group/models/account_move.py @@ -0,0 +1,75 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + amount_total_signed_account_internal_group_equity = fields.Monetary( + compute="_compute_amount_total_signed_account_internal_group" + ) + amount_total_signed_account_internal_group_asset = fields.Monetary( + compute="_compute_amount_total_signed_account_internal_group" + ) + amount_total_signed_account_internal_group_liability = fields.Monetary( + compute="_compute_amount_total_signed_account_internal_group" + ) + amount_total_signed_account_internal_group_income = fields.Monetary( + compute="_compute_amount_total_signed_account_internal_group" + ) + amount_total_signed_account_internal_group_expense = fields.Monetary( + compute="_compute_amount_total_signed_account_internal_group" + ) + amount_total_signed_account_internal_group_off_balance = fields.Monetary( + compute="_compute_amount_total_signed_account_internal_group" + ) + + def _compute_amount_total_signed_account_internal_group(self): + for move in self: + domain = [("move_id", "=", move.id)] + aml_groups = self.env["account.move.line"].read_group( + domain=domain, + fields=["balance", "account_internal_group"], + groupby=["account_internal_group"], + lazy=False, + ) + move.amount_total_signed_account_internal_group_asset = sum( + ag["balance"] + for ag in [ + g for g in aml_groups if g["account_internal_group"] == "asset" + ] + ) + move.amount_total_signed_account_internal_group_equity = sum( + ag["balance"] + for ag in [ + g for g in aml_groups if g["account_internal_group"] == "equity" + ] + ) + move.amount_total_signed_account_internal_group_liability = sum( + ag["balance"] + for ag in [ + g for g in aml_groups if g["account_internal_group"] == "liability" + ] + ) + move.amount_total_signed_account_internal_group_income = sum( + ag["balance"] + for ag in [ + g for g in aml_groups if g["account_internal_group"] == "income" + ] + ) + move.amount_total_signed_account_internal_group_expense = sum( + ag["balance"] + for ag in [ + g for g in aml_groups if g["account_internal_group"] == "expense" + ] + ) + move.amount_total_signed_account_internal_group_off_balance = sum( + ag["balance"] + for ag in [ + g + for g in aml_groups + if g["account_internal_group"] == "off_balance" + ] + ) diff --git a/account_move_total_by_account_internal_group/models/account_move_line.py b/account_move_total_by_account_internal_group/models/account_move_line.py new file mode 100644 index 000000000..6c9f60e92 --- /dev/null +++ b/account_move_total_by_account_internal_group/models/account_move_line.py @@ -0,0 +1,16 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class AccountMoveLine(models.Model): + _inherit = "account.move.line" + + # Making standard field stored in order to do the calculations faster + account_internal_group = fields.Selection( + related="account_id.user_type_id.internal_group", + string="Internal Group", + readonly=True, + store=True, + ) diff --git a/account_move_total_by_account_internal_group/readme/CONTRIBUTORS.rst b/account_move_total_by_account_internal_group/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..8a38830ba --- /dev/null +++ b/account_move_total_by_account_internal_group/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `ForgeFlow `: + + * Aaron Henriquez diff --git a/account_move_total_by_account_internal_group/readme/DESCRIPTION.rst b/account_move_total_by_account_internal_group/readme/DESCRIPTION.rst new file mode 100644 index 000000000..be63758b7 --- /dev/null +++ b/account_move_total_by_account_internal_group/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +Displays the total balance by account internal group in the journal entries. This could +be necesssary in some context. For example, when looking at the stock journal entries +we would like to see the total assets, as long as we would like to see the assets +increasing when there is a debit in the inventory account and deceasing when the +inventory is decreased. The standard field amount_total_signed does not serve, as +it shows this as a positive value in this case. diff --git a/account_move_total_by_account_internal_group/readme/USAGE.rst b/account_move_total_by_account_internal_group/readme/USAGE.rst new file mode 100644 index 000000000..af4771e98 --- /dev/null +++ b/account_move_total_by_account_internal_group/readme/USAGE.rst @@ -0,0 +1 @@ +New hidden columns in journal Entries tree view. diff --git a/account_move_total_by_account_internal_group/static/description/icon.png b/account_move_total_by_account_internal_group/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_move_total_by_account_internal_group/static/description/icon.png differ diff --git a/account_move_total_by_account_internal_group/static/description/index.html b/account_move_total_by_account_internal_group/static/description/index.html new file mode 100644 index 000000000..43c355eee --- /dev/null +++ b/account_move_total_by_account_internal_group/static/description/index.html @@ -0,0 +1,432 @@ + + + + + + +Account Move Total By Account Internal Group + + + +
+

Account Move Total By Account Internal Group

+ + +

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

+

Displays the total balance by account internal group in the journal entries. This could +be necesssary in some context. For example, when looking at the stock journal entries +we would like to see the total assets, as long as we would like to see the assets +increasing when there is a debit in the inventory account and deceasing when the +inventory is decreased. The standard field amount_total_signed does not serve, as +it shows this as a positive value in this case.

+

Table of contents

+ +
+

Usage

+

New hidden columns in journal Entries tree view.

+
+
+

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

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

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_total_by_account_internal_group/tests/__init__.py b/account_move_total_by_account_internal_group/tests/__init__.py new file mode 100644 index 000000000..5ccaccb3b --- /dev/null +++ b/account_move_total_by_account_internal_group/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_account_move_totals_by_account_internal_group diff --git a/account_move_total_by_account_internal_group/tests/test_account_move_totals_by_account_internal_group.py b/account_move_total_by_account_internal_group/tests/test_account_move_totals_by_account_internal_group.py new file mode 100644 index 000000000..208f66a79 --- /dev/null +++ b/account_move_total_by_account_internal_group/tests/test_account_move_totals_by_account_internal_group.py @@ -0,0 +1,123 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestAccountMoveTotalsByAccountType(TransactionCase): + @classmethod + def setUpClass(cls): + super(TestAccountMoveTotalsByAccountType, cls).setUpClass() + cls.account_model = cls.env["account.account"] + cls.acc_type_model = cls.env["account.account.type"] + cls.company = cls.env.ref("base.main_company") + # Create account for Goods Received Not Invoiced + acc_type = cls._create_account_type(cls, "liability", "other") + name = "Goods Received Not Invoiced" + code = "grni" + cls.account_grni = cls._create_account(cls, acc_type, name, code, cls.company) + + # Create account for Cost of Goods Sold + acc_type = cls._create_account_type(cls, "expense", "other") + name = "Cost of Goods Sold" + code = "cogs" + cls.account_cogs = cls._create_account(cls, acc_type, name, code, cls.company) + # Create account for Inventory + acc_type = cls._create_account_type(cls, "asset", "other") + name = "Inventory" + code = "inventory" + cls.account_inventory = cls._create_account( + cls, acc_type, name, code, cls.company + ) + # Create Income account + # Create account for Inventory + acc_type = cls._create_account_type(cls, "income", "other") + name = "Income" + code = "income" + cls.account_income = cls._create_account(cls, acc_type, name, code, cls.company) + cls.journal = cls.env["account.journal"].search( + [("company_id", "=", cls.env.user.company_id.id)], limit=1 + ) + cls.partner = cls.env.ref("base.res_partner_12") + + def _create_account_move(self, dr_account, cr_account): + move_vals = { + "journal_id": self.journal.id, + "date": "1900-01-01", + "line_ids": [ + ( + 0, + 0, + { + "debit": 100.0, + "credit": 0.0, + "account_id": dr_account.id, + "partner_id": self.partner.id, + }, + ), + ( + 0, + 0, + { + "debit": 0.0, + "credit": 100.0, + "account_id": cr_account.id, + "partner_id": self.partner.id, + }, + ), + ], + } + return self.env["account.move"].create(move_vals) + + def _create_account_type(self, name, a_type): + acc_type = self.acc_type_model.create( + {"name": name, "type": a_type, "internal_group": name} + ) + return acc_type + + def _create_account(self, acc_type, name, code, company): + """Create an account.""" + account = self.account_model.create( + { + "name": name, + "code": code, + "user_type_id": acc_type.id, + "company_id": company.id, + "reconcile": True, + } + ) + return account + + def test_01_account_internal_group_balance(self): + """Create JE with different account types and check the amount total + by internal group + """ + account_move = self._create_account_move( + self.account_inventory, self.account_grni + ) + self.assertEqual( + account_move.amount_total_signed_account_internal_group_asset, + 100, + "Wrong asset", + ) + self.assertEqual( + account_move.amount_total_signed_account_internal_group_liability, + -100, + "Wrong liability", + ) + self.assertEqual( + account_move.amount_total_signed_account_internal_group_expense, + 0, + "Wrong expense", + ) + account_move = self._create_account_move(self.account_cogs, self.account_income) + self.assertEqual( + account_move.amount_total_signed_account_internal_group_expense, + 100, + "Wrong Expense", + ) + self.assertEqual( + account_move.amount_total_signed_account_internal_group_income, + -100, + "Wrong Income", + ) diff --git a/account_move_total_by_account_internal_group/views/account_move_views.xml b/account_move_total_by_account_internal_group/views/account_move_views.xml new file mode 100644 index 000000000..6a21fd5c6 --- /dev/null +++ b/account_move_total_by_account_internal_group/views/account_move_views.xml @@ -0,0 +1,53 @@ + + + account.move.user.type.tree + account.move + + + + + + + + + + + + + diff --git a/setup/account_move_total_by_account_internal_group/odoo/addons/account_move_total_by_account_internal_group b/setup/account_move_total_by_account_internal_group/odoo/addons/account_move_total_by_account_internal_group new file mode 120000 index 000000000..cb36e90c8 --- /dev/null +++ b/setup/account_move_total_by_account_internal_group/odoo/addons/account_move_total_by_account_internal_group @@ -0,0 +1 @@ +../../../../account_move_total_by_account_internal_group \ No newline at end of file diff --git a/setup/account_move_total_by_account_internal_group/setup.py b/setup/account_move_total_by_account_internal_group/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_move_total_by_account_internal_group/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)