Skip to content

Commit

Permalink
Merge PR #1287 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed May 2, 2024
2 parents 68c4d54 + fd18fc0 commit 3b50a19
Show file tree
Hide file tree
Showing 16 changed files with 772 additions and 0 deletions.
78 changes: 78 additions & 0 deletions account_move_default_journal/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/account-financial-tools/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 <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_move_default_journal%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Therp BV

Contributors
~~~~~~~~~~~~

* Danny de Jong <[email protected]>

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 <https://github.com/OCA/account-financial-tools/tree/14.0/account_move_default_journal>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions account_move_default_journal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions account_move_default_journal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2021-2023 Therp BV <https://therp.nl>
# 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"],
}
3 changes: 3 additions & 0 deletions account_move_default_journal/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import account_config_settings
from . import account_move
from . import res_company
23 changes: 23 additions & 0 deletions account_move_default_journal/models/account_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2021-2023 Therp BV <https://therp.nl>
# 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",
)
31 changes: 31 additions & 0 deletions account_move_default_journal/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2021-2023 Therp BV <https://therp.nl>
# 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)
17 changes: 17 additions & 0 deletions account_move_default_journal/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 Therp BV <https://therp.nl>
# 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"
)
1 change: 1 addition & 0 deletions account_move_default_journal/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Danny de Jong <[email protected]>
3 changes: 3 additions & 0 deletions account_move_default_journal/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
Loading

0 comments on commit 3b50a19

Please sign in to comment.