From 25e64edab4242de72f60c96632226a10fdbc0a73 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Wed, 6 Nov 2024 11:04:10 +0100 Subject: [PATCH] [IMP] account_reconcile_restrict_partner_mismatch: Avoid restriction on some journals / Enable on company level In some cases, accounting users should be allowed to mix partners. This will be configured on account journal level. In order to not break standard behaviors, the restriction feature should be enabled by a configuration parameter on company level. A new configuration parameter has been added. --- .../README.rst | 13 ++++- .../__manifest__.py | 7 ++- .../models/__init__.py | 3 + .../models/account_journal.py | 13 +++++ .../models/account_move_line.py | 22 +++++--- .../models/res_company.py | 13 +++++ .../models/res_config_settings.py | 13 +++++ .../readme/CONFIGURE.rst | 5 ++ .../readme/DESCRIPTION.rst | 2 + .../static/description/index.html | 56 ++++++++++++------- .../views/account_journal.xml | 22 ++++++++ .../views/res_config_settings.xml | 30 ++++++++++ 12 files changed, 168 insertions(+), 31 deletions(-) create mode 100644 account_reconcile_restrict_partner_mismatch/models/account_journal.py create mode 100644 account_reconcile_restrict_partner_mismatch/models/res_company.py create mode 100644 account_reconcile_restrict_partner_mismatch/models/res_config_settings.py create mode 100644 account_reconcile_restrict_partner_mismatch/readme/CONFIGURE.rst create mode 100644 account_reconcile_restrict_partner_mismatch/views/account_journal.xml create mode 100644 account_reconcile_restrict_partner_mismatch/views/res_config_settings.xml diff --git a/account_reconcile_restrict_partner_mismatch/README.rst b/account_reconcile_restrict_partner_mismatch/README.rst index 6c31f83a..00c5b00d 100644 --- a/account_reconcile_restrict_partner_mismatch/README.rst +++ b/account_reconcile_restrict_partner_mismatch/README.rst @@ -7,7 +7,7 @@ Reconcile restrict partner mismatch !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:e643e776a13ac74578f05aa23fc0328120234f43ff74182e837e0d18e2f357ae + !! source digest: sha256:893e295e519a93dd096174319fa89d25509ab7df53a313bf5cc93c2b98a6be42 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -39,11 +39,22 @@ As at the moment of installation some journal items could have been reconciled using different partners, you can detect them in menu Accounting > Adviser > Reconciled items with partner mismatch. +This restriction can be enabled per company but can also be deactivated per journal. + **Table of contents** .. contents:: :local: +Configuration +============= + +- Go to Accounting > Configuration > Settings > Partners Mismatch Restriction on Reconcile +- Check the box to activate the parameter. +- To deactivate the behavior on journal level, go to Accounting > Configuration > Accounting > Journals +- In Advanced Settings > Partner Mismatch On Reconcile +- Check the box if you want to deactivate the restriction for that journal entries. + Bug Tracker =========== diff --git a/account_reconcile_restrict_partner_mismatch/__manifest__.py b/account_reconcile_restrict_partner_mismatch/__manifest__.py index c8a6481a..46a64f0d 100644 --- a/account_reconcile_restrict_partner_mismatch/__manifest__.py +++ b/account_reconcile_restrict_partner_mismatch/__manifest__.py @@ -11,6 +11,11 @@ "website": "https://github.com/OCA/account-reconcile", "category": "Finance", "license": "AGPL-3", - "data": ["report/account_move_lines_report.xml", "security/ir.model.access.csv"], + "data": [ + "security/ir.model.access.csv", + "report/account_move_lines_report.xml", + "views/account_journal.xml", + "views/res_config_settings.xml", + ], "installable": True, } diff --git a/account_reconcile_restrict_partner_mismatch/models/__init__.py b/account_reconcile_restrict_partner_mismatch/models/__init__.py index 8795b3be..f75ae75d 100644 --- a/account_reconcile_restrict_partner_mismatch/models/__init__.py +++ b/account_reconcile_restrict_partner_mismatch/models/__init__.py @@ -1 +1,4 @@ from . import account_move_line +from . import account_journal +from . import res_company +from . import res_config_settings diff --git a/account_reconcile_restrict_partner_mismatch/models/account_journal.py b/account_reconcile_restrict_partner_mismatch/models/account_journal.py new file mode 100644 index 00000000..b99c05d7 --- /dev/null +++ b/account_reconcile_restrict_partner_mismatch/models/account_journal.py @@ -0,0 +1,13 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class AccountJournal(models.Model): + + _inherit = "account.journal" + + no_restrict_partner_mismatch_on_reconcile = fields.Boolean( + help="Check this if you don't want to restrict partner " + "mismatch (several differents) on reconcile." + ) diff --git a/account_reconcile_restrict_partner_mismatch/models/account_move_line.py b/account_reconcile_restrict_partner_mismatch/models/account_move_line.py index 8f7b7b7b..633e6659 100644 --- a/account_reconcile_restrict_partner_mismatch/models/account_move_line.py +++ b/account_reconcile_restrict_partner_mismatch/models/account_move_line.py @@ -3,25 +3,31 @@ from odoo import _, models from odoo.exceptions import UserError -from odoo.tools import config class AccountMoveLine(models.Model): _inherit = "account.move.line" - def reconcile(self): - if config["test_enable"] and not self.env.context.get("test_partner_mismatch"): - return super().reconcile() + @property + def _check_partner_mismatch_on_reconcile(self): + """ + Returns True if the partner mismatch check on reconcile should be done + """ + self.ensure_one() + return bool( + self.company_id.restrict_partner_mismatch_on_reconcile + and not self.journal_id.no_restrict_partner_mismatch_on_reconcile + and self.account_id.account_type + in ("asset_receivable", "liability_payable") + ) + def reconcile(self): # to be consistent with parent method if not self: return True partners = set() for line in self: - if line.account_id.account_type in ( - "asset_receivable", - "liability_payable", - ): + if line._check_partner_mismatch_on_reconcile: partners.add(line.partner_id.id) if len(partners) > 1: raise UserError( diff --git a/account_reconcile_restrict_partner_mismatch/models/res_company.py b/account_reconcile_restrict_partner_mismatch/models/res_company.py new file mode 100644 index 00000000..03a89437 --- /dev/null +++ b/account_reconcile_restrict_partner_mismatch/models/res_company.py @@ -0,0 +1,13 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class ResCompany(models.Model): + + _inherit = "res.company" + + restrict_partner_mismatch_on_reconcile = fields.Boolean( + help="Check this if you want to avoid partner mismatch" + " (several different partners) on reconciliation." + ) diff --git a/account_reconcile_restrict_partner_mismatch/models/res_config_settings.py b/account_reconcile_restrict_partner_mismatch/models/res_config_settings.py new file mode 100644 index 00000000..2dba2cbc --- /dev/null +++ b/account_reconcile_restrict_partner_mismatch/models/res_config_settings.py @@ -0,0 +1,13 @@ +# Copyright 2024 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + + _inherit = "res.config.settings" + + restrict_partner_mismatch_on_reconcile = fields.Boolean( + related="company_id.restrict_partner_mismatch_on_reconcile", + readonly=False, + ) diff --git a/account_reconcile_restrict_partner_mismatch/readme/CONFIGURE.rst b/account_reconcile_restrict_partner_mismatch/readme/CONFIGURE.rst new file mode 100644 index 00000000..e7bbae30 --- /dev/null +++ b/account_reconcile_restrict_partner_mismatch/readme/CONFIGURE.rst @@ -0,0 +1,5 @@ +- Go to Accounting > Configuration > Settings > Partners Mismatch Restriction on Reconcile +- Check the box to activate the parameter. +- To deactivate the behavior on journal level, go to Accounting > Configuration > Accounting > Journals +- In Advanced Settings > Partner Mismatch On Reconcile +- Check the box if you want to deactivate the restriction for that journal entries. diff --git a/account_reconcile_restrict_partner_mismatch/readme/DESCRIPTION.rst b/account_reconcile_restrict_partner_mismatch/readme/DESCRIPTION.rst index a546b3fa..a5d44a4e 100644 --- a/account_reconcile_restrict_partner_mismatch/readme/DESCRIPTION.rst +++ b/account_reconcile_restrict_partner_mismatch/readme/DESCRIPTION.rst @@ -8,3 +8,5 @@ This rule applies only for journal items using receivable and payable account ty As at the moment of installation some journal items could have been reconciled using different partners, you can detect them in menu Accounting > Adviser > Reconciled items with partner mismatch. + +This restriction can be enabled per company but can also be deactivated per journal. diff --git a/account_reconcile_restrict_partner_mismatch/static/description/index.html b/account_reconcile_restrict_partner_mismatch/static/description/index.html index 25713b75..29317314 100644 --- a/account_reconcile_restrict_partner_mismatch/static/description/index.html +++ b/account_reconcile_restrict_partner_mismatch/static/description/index.html @@ -1,20 +1,20 @@ - - + Reconcile restrict partner mismatch