diff --git a/account_move_change_financial_account/README.rst b/account_move_change_financial_account/README.rst new file mode 100644 index 0000000..ca4961f --- /dev/null +++ b/account_move_change_financial_account/README.rst @@ -0,0 +1,75 @@ +===================================== +Account Move Change Financial Account +===================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-escodoo%2Faccount--addons-lightgray.png?logo=github + :target: https://github.com/escodoo/account-addons/tree/14.0/account_move_change_financial_account + :alt: escodoo/account-addons + +|badge1| |badge2| |badge3| + +This module allows for the automatic changing of financial accounts in accounting move lines (account.move.line) based on predefined rules. This simplifies the application of specific accounting policies without the need for manually adjusting each accounting move. + +Key Features: + +1. Define financial account substitution rules through the account_account_financial_rule class. +2. Apply the substitution rules during the creation of new accounting moves (account.move). +3. Supports rules based on specific criteria, such as the partner involved in the transaction. + +With the account_move_change_financial_account module, users can easily set up and apply custom financial rules, streamlining the accounting process and ensuring compliance with the company's accounting policies. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +- Install the account_move_change_financial_account module. +- Navigate to the financial rules menu (Accounting > Configuration > Financial Rules) and create a new rule by defining the domain condition and the new financial account to be applied. +- When a new accounting move is created and meets the financial rule's domain condition, the financial account of the applicable lines will be automatically changed according to the rule. +- Review the accounting moves to ensure that the financial rules have been correctly applied. + +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 +~~~~~~~ + +* Escodoo + +Contributors +~~~~~~~~~~~~ + +* `Escodoo `_: + + * Marcel Savegnago + +Maintainers +~~~~~~~~~~~ + +This module is part of the `escodoo/account-addons `_ project on GitHub. + +You are welcome to contribute. diff --git a/account_move_change_financial_account/__init__.py b/account_move_change_financial_account/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/account_move_change_financial_account/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_move_change_financial_account/__manifest__.py b/account_move_change_financial_account/__manifest__.py new file mode 100644 index 0000000..ef1c01b --- /dev/null +++ b/account_move_change_financial_account/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2023 - TODAY, Escodoo +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Account Move Change Financial Account", + "summary": """ + Account Move Change Financial Account""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Escodoo", + "website": "https://github.com/Escodoo/account-addons", + "depends": [ + "account", + ], + "data": [ + "security/account_account_financial_rules.xml", + "views/account_account_financial_rules.xml", + ], + "demo": [], +} diff --git a/account_move_change_financial_account/i18n/account_move_change_financial_account.pot b/account_move_change_financial_account/i18n/account_move_change_financial_account.pot new file mode 100644 index 0000000..b4ffcd5 --- /dev/null +++ b/account_move_change_financial_account/i18n/account_move_change_financial_account.pot @@ -0,0 +1,93 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_move_change_financial_account +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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: account_move_change_financial_account +#: model:ir.model,name:account_move_change_financial_account.model_account_account_financial_rules +msgid "Account Account Financial Rules" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.actions.act_window,name:account_move_change_financial_account.account_account_financial_rules_act_window +#: model:ir.ui.menu,name:account_move_change_financial_account.account_account_financial_rules_menu +msgid "Account Financial Rules" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model.fields,field_description:account_move_change_financial_account.field_account_account_financial_rules__financial_account_id +msgid "Account Receivable/Payable" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model.fields,field_description:account_move_change_financial_account.field_account_account_financial_rules__create_uid +msgid "Created by" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model.fields,field_description:account_move_change_financial_account.field_account_account_financial_rules__create_date +msgid "Created on" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model.fields,field_description:account_move_change_financial_account.field_account_account_financial_rules__display_name +msgid "Display Name" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model.fields,field_description:account_move_change_financial_account.field_account_account_financial_rules__domain +msgid "Domain Value" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model.fields,field_description:account_move_change_financial_account.field_account_account_financial_rules__id +msgid "ID" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model,name:account_move_change_financial_account.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model.fields,field_description:account_move_change_financial_account.field_account_account_financial_rules____last_update +msgid "Last Modified on" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model.fields,field_description:account_move_change_financial_account.field_account_account_financial_rules__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model.fields,field_description:account_move_change_financial_account.field_account_account_financial_rules__write_date +msgid "Last Updated on" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model.fields,field_description:account_move_change_financial_account.field_account_account_financial_rules__name +msgid "Name" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model.fields,help:account_move_change_financial_account.field_account_account_financial_rules__domain +msgid "" +"Optional domain filtering of the destination data, as a Python expression" +msgstr "" + +#. module: account_move_change_financial_account +#: model:ir.model.fields,help:account_move_change_financial_account.field_account_account_financial_rules__financial_account_id +msgid "" +"This account will be used instead of the default one as the receivable " +"account for the current partner" +msgstr "" diff --git a/account_move_change_financial_account/models/__init__.py b/account_move_change_financial_account/models/__init__.py new file mode 100644 index 0000000..e1ced8a --- /dev/null +++ b/account_move_change_financial_account/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_move_line +from . import account_account_financial_rules diff --git a/account_move_change_financial_account/models/account_account_financial_rules.py b/account_move_change_financial_account/models/account_account_financial_rules.py new file mode 100644 index 0000000..53d288a --- /dev/null +++ b/account_move_change_financial_account/models/account_account_financial_rules.py @@ -0,0 +1,32 @@ +# Copyright 2023 - TODAY, Marcel Savegnago +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class AccountAccountFinancialRules(models.Model): + + _name = "account.account.financial.rules" + _inherit = ["mail.thread"] + _description = "Account Account Financial Rules" + + name = fields.Char(required=True) + domain = fields.Char( + string="Domain Value", + help="Optional domain filtering of the destination data, as a Python expression", + required=True, + ) + financial_account_id = fields.Many2one( + "account.account", + company_dependent=True, + string="Account Receivable/Payable", + domain="[" + "'|', ('account_type', '=', 'asset_receivable')," + "('account_type', '=', 'liability_payable')," + "('deprecated', '=', False)," + "('company_id', '=', current_company_id)" + "]", + help="This account will be used instead of the default one as the receivable " + "account for the current partner", + required=True, + ) diff --git a/account_move_change_financial_account/models/account_move_line.py b/account_move_change_financial_account/models/account_move_line.py new file mode 100644 index 0000000..f89d4cf --- /dev/null +++ b/account_move_change_financial_account/models/account_move_line.py @@ -0,0 +1,45 @@ +# Copyright 2023 - TODAY, Marcel Savegnago +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import ast + +from odoo import api, models + + +class AccountMoveLine(models.Model): + + _inherit = "account.move.line" + + @api.model_create_multi + def create(self, vals_list): + lines_super = super().create(vals_list) + self._apply_financial_rules(lines_super) + return lines_super + + def _get_financial_lines(self, lines): + return lines.filtered( + lambda line: line.account_id.account_type + in ("asset_receivable", "liability_payable") + ) + + def _apply_financial_rules(self, lines): + financial_lines = self._get_financial_lines(lines) + + if not financial_lines: + return + + domain_ids = self.env["account.account.financial.rules"].search( + [("domain", "!=", False)] + ) + + for domain_id in domain_ids: + if not financial_lines: + break + + domain = ast.literal_eval(domain_id.domain) + lines_to_change = financial_lines.filtered_domain(domain) + + if lines_to_change: + for line in lines_to_change: + line.account_id = domain_id.financial_account_id + financial_lines -= lines_to_change diff --git a/account_move_change_financial_account/readme/CONTRIBUTORS.rst b/account_move_change_financial_account/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..ae453a6 --- /dev/null +++ b/account_move_change_financial_account/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Escodoo `_: + + * Marcel Savegnago diff --git a/account_move_change_financial_account/readme/DESCRIPTION.rst b/account_move_change_financial_account/readme/DESCRIPTION.rst new file mode 100644 index 0000000..76877ba --- /dev/null +++ b/account_move_change_financial_account/readme/DESCRIPTION.rst @@ -0,0 +1,9 @@ +This module allows for the automatic changing of financial accounts in accounting move lines (account.move.line) based on predefined rules. This simplifies the application of specific accounting policies without the need for manually adjusting each accounting move. + +Key Features: + +1. Define financial account substitution rules through the account_account_financial_rule class. +2. Apply the substitution rules during the creation of new accounting moves (account.move). +3. Supports rules based on specific criteria, such as the partner involved in the transaction. + +With the account_move_change_financial_account module, users can easily set up and apply custom financial rules, streamlining the accounting process and ensuring compliance with the company's accounting policies. diff --git a/account_move_change_financial_account/readme/USAGE.rst b/account_move_change_financial_account/readme/USAGE.rst new file mode 100644 index 0000000..3f05f5f --- /dev/null +++ b/account_move_change_financial_account/readme/USAGE.rst @@ -0,0 +1,5 @@ + +- Install the account_move_change_financial_account module. +- Navigate to the financial rules menu (Accounting > Configuration > Account Financial Rules) and create a new rule by defining the domain condition and the new financial account to be applied. +- When a new accounting move is created and meets the financial rule's domain condition, the financial account of the applicable lines will be automatically changed according to the rule. +- Review the accounting moves to ensure that the financial rules have been correctly applied. diff --git a/account_move_change_financial_account/security/account_account_financial_rules.xml b/account_move_change_financial_account/security/account_account_financial_rules.xml new file mode 100644 index 0000000..aa33e51 --- /dev/null +++ b/account_move_change_financial_account/security/account_account_financial_rules.xml @@ -0,0 +1,27 @@ + + + + + + account.account.financial.rules access user + + + + + + + + + + + account.account.financial.rules access manager + + + + + + + + + diff --git a/account_move_change_financial_account/static/description/icon.png b/account_move_change_financial_account/static/description/icon.png new file mode 100644 index 0000000..12ab005 Binary files /dev/null and b/account_move_change_financial_account/static/description/icon.png differ diff --git a/account_move_change_financial_account/static/description/index.html b/account_move_change_financial_account/static/description/index.html new file mode 100644 index 0000000..faae1b3 --- /dev/null +++ b/account_move_change_financial_account/static/description/index.html @@ -0,0 +1,434 @@ + + + + + + +Account Move Change Financial Account + + + +
+

Account Move Change Financial Account

+ + +

Beta License: AGPL-3 escodoo/account-addons

+

This module allows for the automatic changing of financial accounts in accounting move lines (account.move.line) based on predefined rules. This simplifies the application of specific accounting policies without the need for manually adjusting each accounting move.

+

Key Features:

+
    +
  1. Define financial account substitution rules through the account_account_financial_rule class.
  2. +
  3. Apply the substitution rules during the creation of new accounting moves (account.move).
  4. +
  5. Supports rules based on specific criteria, such as the partner involved in the transaction.
  6. +
+

With the account_move_change_financial_account module, users can easily set up and apply custom financial rules, streamlining the accounting process and ensuring compliance with the company’s accounting policies.

+

Table of contents

+ +
+

Usage

+
    +
  • Install the account_move_change_financial_account module.
  • +
  • Navigate to the financial rules menu (Accounting > Configuration > Financial Rules) and create a new rule by defining the domain condition and the new financial account to be applied.
  • +
  • When a new accounting move is created and meets the financial rule’s domain condition, the financial account of the applicable lines will be automatically changed according to the rule.
  • +
  • Review the accounting moves to ensure that the financial rules have been correctly applied.
  • +
+
+
+

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

+
    +
  • Escodoo
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the escodoo/account-addons project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/account_move_change_financial_account/tests/__init__.py b/account_move_change_financial_account/tests/__init__.py new file mode 100644 index 0000000..1c0eead --- /dev/null +++ b/account_move_change_financial_account/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_move_change_financial_account diff --git a/account_move_change_financial_account/tests/test_account_move_change_financial_account.py b/account_move_change_financial_account/tests/test_account_move_change_financial_account.py new file mode 100644 index 0000000..a56b3d6 --- /dev/null +++ b/account_move_change_financial_account/tests/test_account_move_change_financial_account.py @@ -0,0 +1,199 @@ +# Copyright 2023 - TODAY, Marcel Savegnago +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import tagged + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + + +@tagged("post_install", "-at_install") +class TestAccountAccountFinancialRules(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + cls.account_move = cls.env["account.move"] + cls.account_move_line = cls.env["account.move.line"] + cls.financial_rules = cls.env["account.account.financial.rules"] + + cls.partner = cls.env["res.partner"].create( + { + "name": "Test Partner", + } + ) + cls.receivable_account = cls.env["account.account"].search( + [("account_type", "=", "asset_receivable")], limit=1 + ) + cls.revenue_account = cls.env["account.account"].create( + { + "name": "Test Revenue Account", + "code": "TRA", + "account_type": "expense_direct_cost", + } + ) + cls.new_receivable_account = cls.env["account.account"].create( + { + "name": "New Receivable Account", + "code": "NEWRCV", + "account_type": "asset_receivable", + "reconcile": True, + } + ) + + def test_financial_rules_creation(self): + rule = self.financial_rules.create( + { + "name": "Test Rule", + "domain": "[('partner_id', '=', %s)]" % self.partner.id, + "financial_account_id": self.new_receivable_account.id, + } + ) + self.assertTrue(rule) + + def test_account_move_line_creation(self): + self.financial_rules.create( + { + "name": "Test Rule", + "domain": "[('partner_id', '=', %s)]" % self.partner.id, + "financial_account_id": self.new_receivable_account.id, + } + ) + + # Test a rule that will not be applied to any line + self.financial_rules.create( + { + "name": "Test Rule No Match", + "domain": "[('partner_id', '=', -1)]", + "financial_account_id": self.new_receivable_account.id, + } + ) + + move = self.account_move.create( + { + "partner_id": self.partner.id, + "line_ids": [ + ( + 0, + 0, + { + "account_id": self.receivable_account.id, + "partner_id": self.partner.id, + "name": "Receivable line", + "debit": 100.0, + "credit": 0.0, + }, + ), + ( + 0, + 0, + { + "account_id": self.revenue_account.id, + "partner_id": self.partner.id, + "name": "Revenue line", + "debit": 0.0, + "credit": 100.0, + }, + ), + ], + } + ) + + receivable_line = move.line_ids.filtered( + lambda line: line.account_id == self.receivable_account + ) + self.assertFalse(receivable_line) + + new_receivable_line = move.line_ids.filtered( + lambda line: line.account_id == self.new_receivable_account + ) + self.assertTrue(new_receivable_line) + + def test_lines_to_change_no_match(self): + # Test a rule that will not be applied to any line + self.financial_rules.create( + { + "name": "Test Rule No Match", + "domain": "[('partner_id', '=', -1)]", + "financial_account_id": self.new_receivable_account.id, + } + ) + + move = self.account_move.create( + { + "partner_id": self.partner.id, + "line_ids": [ + ( + 0, + 0, + { + "account_id": self.receivable_account.id, + "partner_id": self.partner.id, + "name": "Receivable line", + "debit": 100.0, + "credit": 0.0, + }, + ), + ( + 0, + 0, + { + "account_id": self.revenue_account.id, + "partner_id": self.partner.id, + "name": "Revenue line", + "debit": 0.0, + "credit": 100.0, + }, + ), + ], + } + ) + + # Check if the original receivable account is still used when there's no matching rule + receivable_line = move.line_ids.filtered( + lambda line: line.account_id == self.receivable_account + ) + self.assertTrue(receivable_line) + + # Check if the new_receivable_account is not used when there's no matching rule + new_receivable_line = move.line_ids.filtered( + lambda line: line.account_id == self.new_receivable_account + ) + self.assertFalse(new_receivable_line) + + def test_no_matching_financial_lines(self): + # Test that the code doesn't enter the for loop when there are no financial lines + + move = self.account_move.create( + { + "partner_id": self.partner.id, + "line_ids": [ + ( + 0, + 0, + { + "account_id": self.revenue_account.id, + "partner_id": self.partner.id, + "name": "Revenue line", + "debit": 0.0, + "credit": 100.0, + }, + ), + ( + 0, + 0, + { + "account_id": self.revenue_account.id, + "partner_id": self.partner.id, + "name": "Revenue line 2", + "debit": 100.0, + "credit": 0.0, + }, + ), + ], + } + ) + + # Check if the new_receivable_account is not used when there are no financial lines + new_receivable_line = move.line_ids.filtered( + lambda line: line.account_id == self.new_receivable_account + ) + self.assertFalse(new_receivable_line) diff --git a/account_move_change_financial_account/views/account_account_financial_rules.xml b/account_move_change_financial_account/views/account_account_financial_rules.xml new file mode 100644 index 0000000..d5c9f16 --- /dev/null +++ b/account_move_change_financial_account/views/account_account_financial_rules.xml @@ -0,0 +1,78 @@ + + + + + + account.account.financial.rules.form (in account_move_change_financial_account) + account.account.financial.rules + +
+
+ +
+ + + + + + + +
+ + + + + + account.account.financial.rules.search (in account_move_change_financial_account) + account.account.financial.rules + + + + + + + + + + + account.account.financial.rules.tree (in account_move_change_financial_account) + account.account.financial.rules + + + + + + + + + + + Account Financial Rules + account.account.financial.rules + tree,form + [] + {} + + + + Account Financial Rules + + + + + + diff --git a/setup/account_move_change_financial_account/odoo/addons/account_move_change_financial_account b/setup/account_move_change_financial_account/odoo/addons/account_move_change_financial_account new file mode 120000 index 0000000..57ebffc --- /dev/null +++ b/setup/account_move_change_financial_account/odoo/addons/account_move_change_financial_account @@ -0,0 +1 @@ +../../../../account_move_change_financial_account \ No newline at end of file diff --git a/setup/account_move_change_financial_account/setup.py b/setup/account_move_change_financial_account/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/account_move_change_financial_account/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)