diff --git a/account_reconcile_model_strict_match_amount/__init__.py b/account_reconcile_model_strict_match_amount/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/account_reconcile_model_strict_match_amount/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_reconcile_model_strict_match_amount/__manifest__.py b/account_reconcile_model_strict_match_amount/__manifest__.py new file mode 100644 index 00000000..b5ed811d --- /dev/null +++ b/account_reconcile_model_strict_match_amount/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +{ + "name": "Account Reconciliation Model Strict Match Amount", + "summary": "Restrict reconciliation propositions to matching amount parameter", + "version": "13.0.1.0.0", + "category": "Accounting", + "website": "https://github.com/OCA/account-reconcile", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["account"], + "data": ["views/account_reconcile_model.xml"], +} diff --git a/account_reconcile_model_strict_match_amount/models/__init__.py b/account_reconcile_model_strict_match_amount/models/__init__.py new file mode 100644 index 00000000..e27d0c6c --- /dev/null +++ b/account_reconcile_model_strict_match_amount/models/__init__.py @@ -0,0 +1 @@ +from . import account_reconcile_model diff --git a/account_reconcile_model_strict_match_amount/models/account_reconcile_model.py b/account_reconcile_model_strict_match_amount/models/account_reconcile_model.py new file mode 100644 index 00000000..16e1a17d --- /dev/null +++ b/account_reconcile_model_strict_match_amount/models/account_reconcile_model.py @@ -0,0 +1,76 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import fields, models + + +class AccountReconcileModel(models.Model): + + _inherit = "account.reconcile.model" + + strict_match_total_amount = fields.Boolean( + string="Strict Amount Matching", + help="Avoid bypassing the Amount Matching parameter in case of a " + "statement line communication matching exactly existing entries.", + ) + + # flake8: noqa + + def _get_select_communication_flag(self): + if not self.match_total_amount or not self.strict_match_total_amount: + return super()._get_select_communication_flag() + else: + return r""" + -- Determine a matching or not with the statement line communication using the aml.name, move.name or move.ref. + COALESCE( + ( + aml.name IS NOT NULL + AND + substring(REGEXP_REPLACE(aml.name, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*') != '' + AND + regexp_split_to_array(substring(REGEXP_REPLACE(aml.name, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'),'\s+') + && regexp_split_to_array(substring(REGEXP_REPLACE(st_line.name, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'), '\s+') + ) + OR + regexp_split_to_array(substring(REGEXP_REPLACE(move.name, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'),'\s+') + && regexp_split_to_array(substring(REGEXP_REPLACE(st_line.name, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'), '\s+') + OR + ( + move.ref IS NOT NULL + AND + substring(REGEXP_REPLACE(move.ref, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*') != '' + AND + regexp_split_to_array(substring(REGEXP_REPLACE(move.ref, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'),'\s+') + && regexp_split_to_array(substring(REGEXP_REPLACE(st_line.name, '[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'), '\s+') + ) + , FALSE) + AND + CASE + WHEN abs(st_line.amount) < abs(aml.balance) THEN abs(st_line.amount) / abs(aml.balance) * 100 + WHEN abs(st_line.amount) > abs(aml.balance) THEN abs(aml.balance) / abs(st_line.amount) * 100 + ELSE 100 + END >= {match_total_amount_param} AS communication_flag + """.format( + match_total_amount_param=self.match_total_amount_param + ) + + def _get_select_payment_reference_flag(self): + if not self.match_total_amount or not self.strict_match_total_amount: + return super()._get_select_payment_reference_flag() + else: + return r""" + -- Determine a matching or not with the statement line communication using the move.invoice_payment_ref. + COALESCE + ( + move.invoice_payment_ref IS NOT NULL + AND + regexp_replace(move.invoice_payment_ref, '\s+', '', 'g') = regexp_replace(st_line.name, '\s+', '', 'g') + , FALSE) + AND + CASE + WHEN abs(st_line.amount) < abs(aml.balance) THEN abs(st_line.amount) / abs(aml.balance) * 100 + WHEN abs(st_line.amount) > abs(aml.balance) THEN abs(aml.balance) / abs(st_line.amount) * 100 + ELSE 100 + END >= {match_total_amount_param} AS payment_reference_flag + """.format( + match_total_amount_param=self.match_total_amount_param + ) diff --git a/account_reconcile_model_strict_match_amount/readme/CONTRIBUTORS.rst b/account_reconcile_model_strict_match_amount/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..e31e2f0c --- /dev/null +++ b/account_reconcile_model_strict_match_amount/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Akim Juillerat diff --git a/account_reconcile_model_strict_match_amount/readme/DESCRIPTION.rst b/account_reconcile_model_strict_match_amount/readme/DESCRIPTION.rst new file mode 100644 index 00000000..0c77d35b --- /dev/null +++ b/account_reconcile_model_strict_match_amount/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module allows to cancel the bypassing of Amount Matching feature on +Reconciliation models "in case of a statement line communication matching +exactly existing entries", to ensure only statement lines matching the total +amount (or according to its percentage) will be reconciled automatically. diff --git a/account_reconcile_model_strict_match_amount/tests/__init__.py b/account_reconcile_model_strict_match_amount/tests/__init__.py new file mode 100644 index 00000000..97a05422 --- /dev/null +++ b/account_reconcile_model_strict_match_amount/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_reconcile_model_strict_match_amount diff --git a/account_reconcile_model_strict_match_amount/tests/test_account_reconcile_model_strict_match_amount.py b/account_reconcile_model_strict_match_amount/tests/test_account_reconcile_model_strict_match_amount.py new file mode 100644 index 00000000..c9582be6 --- /dev/null +++ b/account_reconcile_model_strict_match_amount/tests/test_account_reconcile_model_strict_match_amount.py @@ -0,0 +1,130 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo.addons.account.tests.test_reconciliation_matching_rules import ( + TestReconciliationMatchingRules, +) + + +class TestAccountReconcileModelStrictMatchAmount(TestReconciliationMatchingRules): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner_3 = cls.env["res.partner"].create({"name": "partner_3"}) + cls.partner_4 = cls.env["res.partner"].create({"name": "partner_4"}) + cls.partner_5 = cls.env["res.partner"].create({"name": "partner_5"}) + cls.partner_6 = cls.env["res.partner"].create({"name": "partner_6"}) + cls.invoice_line_5 = cls._create_invoice_line(150, cls.partner_3, "out_invoice") + cls.invoice_line_5.ref = "ABC001XYZ" + cls.invoice_line_6 = cls._create_invoice_line(300, cls.partner_4, "out_invoice") + cls.invoice_line_6.name = "ABC002XYZ" + cls.invoice_line_7 = cls._create_invoice_line(450, cls.partner_5, "out_invoice") + cls.invoice_line_7.move_id.ref = "ABC003XYZ" + cls.invoice_line_8 = cls._create_invoice_line(600, cls.partner_6, "out_invoice") + cls.invoice_line_8.move_id.invoice_payment_ref = "ABC004XYZ" + cls.bank_st_2 = cls.env["account.bank.statement"].create( + { + "name": "test bank journal 2", + "journal_id": cls.company_data["default_journal_bank"].id, + } + ) + + cls.bank_line_3 = cls.env["account.bank.statement.line"].create( + { + "statement_id": cls.bank_st_2.id, + "name": "ABC001XYZ", + "partner_id": cls.partner_3.id, + "amount": 135, + "sequence": 1, + } + ) + cls.bank_line_4 = cls.env["account.bank.statement.line"].create( + { + "statement_id": cls.bank_st_2.id, + "name": "ABC002XYZ", + "partner_id": cls.partner_4.id, + "amount": 270, + "sequence": 2, + } + ) + cls.bank_line_5 = cls.env["account.bank.statement.line"].create( + { + "statement_id": cls.bank_st_2.id, + "name": "ABC003XYZ", + "partner_id": cls.partner_5.id, + "amount": 405, + "sequence": 3, + } + ) + cls.bank_line_6 = cls.env["account.bank.statement.line"].create( + { + "statement_id": cls.bank_st_2.id, + "name": "ABC004XYZ", + "partner_id": cls.partner_6.id, + "amount": 540, + "sequence": 4, + } + ) + + def test_auto_reconcile_strict_match_100(self): + my_rule = self.env["account.reconcile.model"].create( + { + "name": "Strict Invoice matching amount 100%", + "rule_type": "invoice_matching", + "auto_reconcile": True, + "match_nature": "both", + "match_same_currency": True, + "match_total_amount": True, + "match_total_amount_param": 100.0, + "strict_match_total_amount": True, + } + ) + self._check_statement_matching( + my_rule, + { + self.bank_line_3.id: {"aml_ids": []}, + self.bank_line_4.id: {"aml_ids": []}, + self.bank_line_5.id: {"aml_ids": []}, + self.bank_line_6.id: {"aml_ids": []}, + }, + statements=self.bank_st_2, + ) + + def test_auto_reconcile_strict_match_90(self): + my_rule = self.env["account.reconcile.model"].create( + { + "name": "Strict Invoice matching amount 90%", + "rule_type": "invoice_matching", + "auto_reconcile": True, + "match_nature": "both", + "match_same_currency": True, + "match_total_amount": True, + "match_total_amount_param": 90.0, + "strict_match_total_amount": True, + } + ) + self._check_statement_matching( + my_rule, + { + self.bank_line_3.id: { + "aml_ids": [self.invoice_line_5.id], + "model": my_rule, + "status": "reconciled", + }, + self.bank_line_4.id: { + "aml_ids": [self.invoice_line_6.id], + "model": my_rule, + "status": "reconciled", + }, + self.bank_line_5.id: { + "aml_ids": [self.invoice_line_7.id], + "model": my_rule, + "status": "reconciled", + }, + self.bank_line_6.id: { + "aml_ids": [self.invoice_line_8.id], + "model": my_rule, + "status": "reconciled", + }, + }, + statements=self.bank_st_2, + ) diff --git a/account_reconcile_model_strict_match_amount/views/account_reconcile_model.xml b/account_reconcile_model_strict_match_amount/views/account_reconcile_model.xml new file mode 100644 index 00000000..a55833fe --- /dev/null +++ b/account_reconcile_model_strict_match_amount/views/account_reconcile_model.xml @@ -0,0 +1,24 @@ + + + + account.reconcile.model.form + account.reconcile.model + + + + + + + {'invisible': ['|', '|', ('rule_type', '!=', 'invoice_matching'), ('match_total_amount', '=', False), ('strict_match_total_amount', '=', True)]} + + + + diff --git a/setup/account_reconcile_model_strict_match_amount/odoo/addons/account_reconcile_model_strict_match_amount b/setup/account_reconcile_model_strict_match_amount/odoo/addons/account_reconcile_model_strict_match_amount new file mode 120000 index 00000000..96241da0 --- /dev/null +++ b/setup/account_reconcile_model_strict_match_amount/odoo/addons/account_reconcile_model_strict_match_amount @@ -0,0 +1 @@ +../../../../account_reconcile_model_strict_match_amount \ No newline at end of file diff --git a/setup/account_reconcile_model_strict_match_amount/setup.py b/setup/account_reconcile_model_strict_match_amount/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_reconcile_model_strict_match_amount/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)