From cc8c6fc19315c0cd84057757dfd4289e4e8038da Mon Sep 17 00:00:00 2001 From: Danny de Jong Date: Thu, 31 Aug 2023 17:02:30 +0200 Subject: [PATCH 1/2] [ADD] account_move_default_journal: A module to have more meaningful default journals in account move forms. --- account_move_default_journal/__init__.py | 1 + account_move_default_journal/__manifest__.py | 15 ++++ .../models/__init__.py | 3 + .../models/account_config_settings.py | 23 ++++++ .../models/account_move.py | 31 ++++++++ .../models/res_company.py | 17 ++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 3 + .../tests/__init__.py | 1 + .../tests/test_defaults.py | 79 +++++++++++++++++++ .../views/account_config_settings.xml | 63 +++++++++++++++ .../views/res_company_views.xml | 27 +++++++ 12 files changed, 264 insertions(+) create mode 100644 account_move_default_journal/__init__.py create mode 100644 account_move_default_journal/__manifest__.py create mode 100644 account_move_default_journal/models/__init__.py create mode 100644 account_move_default_journal/models/account_config_settings.py create mode 100644 account_move_default_journal/models/account_move.py create mode 100644 account_move_default_journal/models/res_company.py create mode 100644 account_move_default_journal/readme/CONTRIBUTORS.rst create mode 100644 account_move_default_journal/readme/DESCRIPTION.rst create mode 100644 account_move_default_journal/tests/__init__.py create mode 100644 account_move_default_journal/tests/test_defaults.py create mode 100644 account_move_default_journal/views/account_config_settings.xml create mode 100644 account_move_default_journal/views/res_company_views.xml diff --git a/account_move_default_journal/__init__.py b/account_move_default_journal/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/account_move_default_journal/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_move_default_journal/__manifest__.py b/account_move_default_journal/__manifest__.py new file mode 100644 index 00000000000..140bb99f27b --- /dev/null +++ b/account_move_default_journal/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2021-2023 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Default Journal", + "version": "14.0.1.0.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Accounting & Finance", + "summary": "Configure a default journal for new account moves", + "website": "https://github.com/OCA/account-financial-tools", + "depends": [ + "account", + ], + "data": ["views/account_config_settings.xml", "views/res_company_views.xml"], +} diff --git a/account_move_default_journal/models/__init__.py b/account_move_default_journal/models/__init__.py new file mode 100644 index 00000000000..5c764fc0cf5 --- /dev/null +++ b/account_move_default_journal/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_config_settings +from . import account_move +from . import res_company diff --git a/account_move_default_journal/models/account_config_settings.py b/account_move_default_journal/models/account_config_settings.py new file mode 100644 index 00000000000..0c7f0b5f5ab --- /dev/null +++ b/account_move_default_journal/models/account_config_settings.py @@ -0,0 +1,23 @@ +# Copyright 2021-2023 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + account_move_default_general_journal_id = fields.Many2one( + "account.journal", + string="Default journal for new miscellaneous bookings", + related="company_id.default_general_journal_id", + ) + account_move_default_sale_journal_id = fields.Many2one( + "account.journal", + string="Default journal for new sale bookings", + related="company_id.default_sale_journal_id", + ) + account_move_default_purchase_journal_id = fields.Many2one( + "account.journal", + string="Default journal for new purchase bookings", + related="company_id.default_purchase_journal_id", + ) diff --git a/account_move_default_journal/models/account_move.py b/account_move_default_journal/models/account_move.py new file mode 100644 index 00000000000..50621b3db7b --- /dev/null +++ b/account_move_default_journal/models/account_move.py @@ -0,0 +1,31 @@ +# Copyright 2021-2023 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + @api.model + def _search_default_journal(self, journal_types): + company_id = self._context.get("default_company_id", self.env.company.id) + company = self.env["res.company"].browse(company_id) + + # Use the appropriate config parameter for the journal type + journal = None + if "sale" in journal_types: + journal = company.default_sale_journal_id + elif "purchase" in journal_types: + journal = company.default_purchase_journal_id + elif "general" in journal_types: + journal = company.default_general_journal_id + + # Use the found journal, otherwise default back to normal behavior + if journal: + default_currency_id = self._context.get("default_currency_id") + if ( + not default_currency_id + or journal.currency_id.id == default_currency_id.id + ): + return journal + return super()._search_default_journal(journal_types) diff --git a/account_move_default_journal/models/res_company.py b/account_move_default_journal/models/res_company.py new file mode 100644 index 00000000000..ebc9dbfc411 --- /dev/null +++ b/account_move_default_journal/models/res_company.py @@ -0,0 +1,17 @@ +# Copyright 2023 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + default_general_journal_id = fields.Many2one( + "account.journal", string="Default journal for new general bookings" + ) + default_sale_journal_id = fields.Many2one( + "account.journal", string="Default journal for new sale bookings" + ) + default_purchase_journal_id = fields.Many2one( + "account.journal", string="Default journal for new purchase bookings" + ) diff --git a/account_move_default_journal/readme/CONTRIBUTORS.rst b/account_move_default_journal/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..4d02b8616de --- /dev/null +++ b/account_move_default_journal/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Danny de Jong diff --git a/account_move_default_journal/readme/DESCRIPTION.rst b/account_move_default_journal/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..2b0570c06eb --- /dev/null +++ b/account_move_default_journal/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module allows you to set defaults for journals, so that default values for +the journal field in forms can be configured. For one, this prevents users from +accidentally picking an old journal that gets usually offered as a default. diff --git a/account_move_default_journal/tests/__init__.py b/account_move_default_journal/tests/__init__.py new file mode 100644 index 00000000000..0ff10649d11 --- /dev/null +++ b/account_move_default_journal/tests/__init__.py @@ -0,0 +1 @@ +from . import test_defaults diff --git a/account_move_default_journal/tests/test_defaults.py b/account_move_default_journal/tests/test_defaults.py new file mode 100644 index 00000000000..b60959e5a33 --- /dev/null +++ b/account_move_default_journal/tests/test_defaults.py @@ -0,0 +1,79 @@ +# Copyright 2023 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo.tests import TransactionCase + + +class TestDefaults(TransactionCase): + def setUp(self): + super().setUp() + self.different_currency = self.env["res.currency"].create( + { + "name": "Test Currency", + "symbol": "?", + } + ) + self.company = self.env.ref("base.main_company") + # This journal gets selected before the 'General Journal' because of its code: + self.journal_first = self.env["account.journal"].create( + { + "name": "First Journal", + "code": "1st", + "type": "general", + "company_id": self.company.id, + } + ) + self.journal_general = self.env["account.journal"].create( + { + "name": "General Journal", + "code": "GJ", + "type": "general", + "company_id": self.company.id, + "currency_id": self.different_currency.id, + } + ) + self.journal_sale = self.env["account.journal"].create( + { + "name": "Sale Journal", + "code": "SJ", + "type": "sale", + "company_id": self.company.id, + } + ) + self.journal_purchase = self.env["account.journal"].create( + { + "name": "Purchase Journal", + "code": "PJ", + "type": "purchase", + "company_id": self.company.id, + } + ) + + def test_defaults(self): + # Test whether the first journal gets selected with no default set + move = self.env["account.move"].create({"move_type": "entry"}) + self.assertNotEqual(move.journal_id, self.journal_general) + + # Test whether the journal with the relevant currency is chosen + move = ( + self.env["account.move"] + .with_context({"default_currency_id": self.different_currency.id}) + .create({"move_type": "entry"}) + ) + self.assertEqual(move.journal_id, self.journal_general) + move = ( + self.env["account.move"] + .with_context({"default_currency_id": self.different_currency.id}) + .create({"move_type": "out_invoice"}) + ) + self.assertNotEqual(move.journal_id, self.journal_general) + + # Test whether the correct default journals are chosen + self.company.default_general_journal_id = self.journal_general + self.company.default_sale_journal_id = self.journal_sale + self.company.default_purchase_journal_id = self.journal_purchase + move = self.env["account.move"].create({"move_type": "entry"}) + self.assertEqual(move.journal_id, self.journal_general) + move = self.env["account.move"].create({"move_type": "out_invoice"}) + self.assertEqual(move.journal_id, self.journal_sale) + move = self.env["account.move"].create({"move_type": "in_invoice"}) + self.assertEqual(move.journal_id, self.journal_purchase) diff --git a/account_move_default_journal/views/account_config_settings.xml b/account_move_default_journal/views/account_config_settings.xml new file mode 100644 index 00000000000..ce4d0731fd1 --- /dev/null +++ b/account_move_default_journal/views/account_config_settings.xml @@ -0,0 +1,63 @@ + + + + res.config.settings.view.form.inherit.journals + res.config.settings + + + +

Journals

+
+
+
+
+
+ Default Journals +
+ Default journals for new bookings and invoices. +
+
+
+
+
+
+
+
+
+
+
+
+ + + + diff --git a/account_move_default_journal/views/res_company_views.xml b/account_move_default_journal/views/res_company_views.xml new file mode 100644 index 00000000000..60ad713fa9b --- /dev/null +++ b/account_move_default_journal/views/res_company_views.xml @@ -0,0 +1,27 @@ + + + + res.company.form + res.company + + + + + + + + + + From fd18fc0239faabcdec5d09aadcb678d7fbe7de49 Mon Sep 17 00:00:00 2001 From: Danny de Jong Date: Mon, 20 Nov 2023 20:11:50 +0100 Subject: [PATCH 2/2] [ADD] account_move_default_journal: Added pre-commit generated files. --- account_move_default_journal/README.rst | 78 ++++ .../static/description/index.html | 423 ++++++++++++++++++ .../odoo/addons/account_move_default_journal | 1 + setup/account_move_default_journal/setup.py | 6 + 4 files changed, 508 insertions(+) create mode 100644 account_move_default_journal/README.rst create mode 100644 account_move_default_journal/static/description/index.html create mode 120000 setup/account_move_default_journal/odoo/addons/account_move_default_journal create mode 100644 setup/account_move_default_journal/setup.py diff --git a/account_move_default_journal/README.rst b/account_move_default_journal/README.rst new file mode 100644 index 00000000000..3cb36823898 --- /dev/null +++ b/account_move_default_journal/README.rst @@ -0,0 +1,78 @@ +=============== +Default Journal +=============== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f33e4485f28054a33153b02f5ee4952307604625023266d244907023c98a0949 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/14.0/account_move_default_journal + :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-14-0/account-financial-tools-14-0-account_move_default_journal + :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-tools&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows you to set defaults for journals, so that default values for +the journal field in forms can be configured. For one, this prevents users from +accidentally picking an old journal that gets usually offered as a default. + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Therp BV + +Contributors +~~~~~~~~~~~~ + +* Danny de Jong + +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_default_journal/static/description/index.html b/account_move_default_journal/static/description/index.html new file mode 100644 index 00000000000..3d6524b39d6 --- /dev/null +++ b/account_move_default_journal/static/description/index.html @@ -0,0 +1,423 @@ + + + + + + +Default Journal + + + +
+

Default Journal

+ + +

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

+

This module allows you to set defaults for journals, so that default values for +the journal field in forms can be configured. For one, this prevents users from +accidentally picking an old journal that gets usually offered as a default.

+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Therp BV
  • +
+
+
+

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/setup/account_move_default_journal/odoo/addons/account_move_default_journal b/setup/account_move_default_journal/odoo/addons/account_move_default_journal new file mode 120000 index 00000000000..df92acd78d2 --- /dev/null +++ b/setup/account_move_default_journal/odoo/addons/account_move_default_journal @@ -0,0 +1 @@ +../../../../account_move_default_journal \ No newline at end of file diff --git a/setup/account_move_default_journal/setup.py b/setup/account_move_default_journal/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/account_move_default_journal/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)