From e16a570103cd79155666aa6efe17ee1762d4beb2 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 21 Jan 2020 12:31:20 +0100 Subject: [PATCH 1/3] [ADD] account_reconcile_model_strict_match_amount --- .../__init__.py | 1 + .../__manifest__.py | 19 +++++ .../models/__init__.py | 1 + .../models/account_reconcile_model.py | 42 ++++++++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 4 + .../tests/__init__.py | 1 + ...unt_reconcile_model_strict_match_amount.py | 80 +++++++++++++++++++ .../views/account_reconcile_model.xml | 16 ++++ 9 files changed, 165 insertions(+) create mode 100644 account_reconcile_model_strict_match_amount/__init__.py create mode 100644 account_reconcile_model_strict_match_amount/__manifest__.py create mode 100644 account_reconcile_model_strict_match_amount/models/__init__.py create mode 100644 account_reconcile_model_strict_match_amount/models/account_reconcile_model.py create mode 100644 account_reconcile_model_strict_match_amount/readme/CONTRIBUTORS.rst create mode 100644 account_reconcile_model_strict_match_amount/readme/DESCRIPTION.rst create mode 100644 account_reconcile_model_strict_match_amount/tests/__init__.py create mode 100644 account_reconcile_model_strict_match_amount/tests/test_account_reconcile_model_strict_match_amount.py create mode 100644 account_reconcile_model_strict_match_amount/views/account_reconcile_model.xml 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..78335557 --- /dev/null +++ b/account_reconcile_model_strict_match_amount/__manifest__.py @@ -0,0 +1,19 @@ +# 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": "12.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..fcdc395c --- /dev/null +++ b/account_reconcile_model_strict_match_amount/models/account_reconcile_model.py @@ -0,0 +1,42 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import api, 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." + ) + + @api.multi + 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: + regexp = r"'[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'), '\s+'" + return r''' + -- Determine a matching or not with the statement line communication using the move.name or move.ref. + -- only digits are considered and reference are split by any space characters + COALESCE( + regexp_split_to_array(substring(REGEXP_REPLACE(move.name, {regexp}) + && regexp_split_to_array(substring(REGEXP_REPLACE(st_line.name, {regexp}) + OR + ( + move.ref IS NOT NULL + AND + regexp_split_to_array(substring(REGEXP_REPLACE(move.ref, {regexp}) + && + regexp_split_to_array(substring(REGEXP_REPLACE(st_line.name, {regexp}) + ), 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(regexp=regexp, 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..e6c8f518 --- /dev/null +++ b/account_reconcile_model_strict_match_amount/tests/test_account_reconcile_model_strict_match_amount.py @@ -0,0 +1,80 @@ +# 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): + + def setUp(self): + super().setUp() + self.partner_3 = self.env['res.partner'].create({'name': 'partner_3'}) + self.partner_4 = self.env['res.partner'].create({'name': 'partner_4'}) + self.invoice_line_5 = self._create_invoice_line( + 150, self.partner_3, 'out_invoice' + ) + self.invoice_line_5.ref = 'ABC001XYZ' + self.invoice_line_6 = self._create_invoice_line( + 300, self.partner_4, 'out_invoice' + ) + self.invoice_line_6.name = 'ABC002XYZ' + + self.bank_st_2 = self.env['account.bank.statement'].create({ + 'name': 'test bank journal 2', 'journal_id': self.bank_journal.id, + }) + + self.bank_line_3 = self.env['account.bank.statement.line'].create({ + 'statement_id': self.bank_st_2.id, + 'name': 'ABC001XYZ', + 'partner_id': self.partner_3.id, + 'amount': 70, + 'sequence': 1, + }) + self.bank_line_4 = self.env['account.bank.statement.line'].create({ + 'statement_id': self.bank_st_2.id, + 'name': 'ABC002XYZ', + 'partner_id': self.partner_4.id, + 'amount': 270, + 'sequence': 1, + }) + + 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_partner': True, + 'match_same_currency': True, + 'match_total_amount': True, + 'match_total_amount_param': 100.0, + 'strict_match_total_amount': True, + # 'match_partner_ids': [ + # (6, 0, [self.partner_3.id, self.partner_4.id]) + # ], + }) + + self._check_statement_matching(my_rule, { + self.bank_line_3.id: {'aml_ids': []}, + self.bank_line_4.id: {'aml_ids': []}, + }, statements=self.bank_st_2) + + def test_auto_reconcile_strict_match_80(self): + my_rule = self.env['account.reconcile.model'].create({ + 'name': 'Strict Invoice matching amount 80%', + 'rule_type': 'invoice_matching', + 'auto_reconcile': True, + 'match_nature': 'both', + 'match_partner': True, + 'match_same_currency': True, + 'match_total_amount': True, + 'match_total_amount_param': 80.0, + 'strict_match_total_amount': True, + # 'match_partner_ids': [ + # (6, 0, [self.partner_3.id, self.partner_4.id]) + # ], + }) + + self._check_statement_matching(my_rule, { + self.bank_line_3.id: {'aml_ids': []}, + self.bank_line_4.id: {'aml_ids': [self.invoice_line_6.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..33fd273b --- /dev/null +++ b/account_reconcile_model_strict_match_amount/views/account_reconcile_model.xml @@ -0,0 +1,16 @@ + + + + account.reconcile.model.form + account.reconcile.model + + + + + + + {'invisible': ['|', '|', ('rule_type', '!=', 'invoice_matching'), ('match_total_amount', '=', False), ('strict_match_total_amount', '=', True)]} + + + + From 57dea6cb72d92529b8fcb9212b766f29779ac239 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Wed, 29 Apr 2020 15:03:18 +0200 Subject: [PATCH 2/3] [IMP] account_reconcile_model_strict_match_amount: black, isort, prettier --- .../__manifest__.py | 8 +- .../models/account_reconcile_model.py | 10 +- ...unt_reconcile_model_strict_match_amount.py | 143 ++++++++++-------- .../views/account_reconcile_model.xml | 16 +- ...ccount_reconcile_model_strict_match_amount | 1 + .../setup.py | 6 + 6 files changed, 109 insertions(+), 75 deletions(-) create mode 120000 setup/account_reconcile_model_strict_match_amount/odoo/addons/account_reconcile_model_strict_match_amount create mode 100644 setup/account_reconcile_model_strict_match_amount/setup.py diff --git a/account_reconcile_model_strict_match_amount/__manifest__.py b/account_reconcile_model_strict_match_amount/__manifest__.py index 78335557..c3c7b495 100644 --- a/account_reconcile_model_strict_match_amount/__manifest__.py +++ b/account_reconcile_model_strict_match_amount/__manifest__.py @@ -10,10 +10,6 @@ "license": "AGPL-3", "application": False, "installable": True, - "depends": [ - "account", - ], - "data": [ - "views/account_reconcile_model.xml", - ], + "depends": ["account",], + "data": ["views/account_reconcile_model.xml",], } 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 index fcdc395c..8bb38216 100644 --- a/account_reconcile_model_strict_match_amount/models/account_reconcile_model.py +++ b/account_reconcile_model_strict_match_amount/models/account_reconcile_model.py @@ -5,12 +5,12 @@ from odoo import api, fields, models class AccountReconcileModel(models.Model): - _inherit = 'account.reconcile.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." + "statement line communication matching exactly existing entries.", ) @api.multi @@ -19,7 +19,7 @@ class AccountReconcileModel(models.Model): return super()._get_select_communication_flag() else: regexp = r"'[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'), '\s+'" - return r''' + return r""" -- Determine a matching or not with the statement line communication using the move.name or move.ref. -- only digits are considered and reference are split by any space characters COALESCE( @@ -39,4 +39,6 @@ class AccountReconcileModel(models.Model): 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(regexp=regexp, match_total_amount_param=self.match_total_amount_param) + """.format( + regexp=regexp, match_total_amount_param=self.match_total_amount_param + ) 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 index e6c8f518..ca7f5d8a 100644 --- 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 @@ -1,80 +1,101 @@ # 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 +from odoo.addons.account.tests.test_reconciliation_matching_rules import ( + TestReconciliationMatchingRules, +) class TestAccountReconcileModelStrictMatchAmount(TestReconciliationMatchingRules): - def setUp(self): super().setUp() - self.partner_3 = self.env['res.partner'].create({'name': 'partner_3'}) - self.partner_4 = self.env['res.partner'].create({'name': 'partner_4'}) + self.partner_3 = self.env["res.partner"].create({"name": "partner_3"}) + self.partner_4 = self.env["res.partner"].create({"name": "partner_4"}) self.invoice_line_5 = self._create_invoice_line( - 150, self.partner_3, 'out_invoice' + 150, self.partner_3, "out_invoice" ) - self.invoice_line_5.ref = 'ABC001XYZ' + self.invoice_line_5.ref = "ABC001XYZ" self.invoice_line_6 = self._create_invoice_line( - 300, self.partner_4, 'out_invoice' + 300, self.partner_4, "out_invoice" ) - self.invoice_line_6.name = 'ABC002XYZ' + self.invoice_line_6.name = "ABC002XYZ" - self.bank_st_2 = self.env['account.bank.statement'].create({ - 'name': 'test bank journal 2', 'journal_id': self.bank_journal.id, - }) + self.bank_st_2 = self.env["account.bank.statement"].create( + {"name": "test bank journal 2", "journal_id": self.bank_journal.id,} + ) - self.bank_line_3 = self.env['account.bank.statement.line'].create({ - 'statement_id': self.bank_st_2.id, - 'name': 'ABC001XYZ', - 'partner_id': self.partner_3.id, - 'amount': 70, - 'sequence': 1, - }) - self.bank_line_4 = self.env['account.bank.statement.line'].create({ - 'statement_id': self.bank_st_2.id, - 'name': 'ABC002XYZ', - 'partner_id': self.partner_4.id, - 'amount': 270, - 'sequence': 1, - }) + self.bank_line_3 = self.env["account.bank.statement.line"].create( + { + "statement_id": self.bank_st_2.id, + "name": "ABC001XYZ", + "partner_id": self.partner_3.id, + "amount": 70, + "sequence": 1, + } + ) + self.bank_line_4 = self.env["account.bank.statement.line"].create( + { + "statement_id": self.bank_st_2.id, + "name": "ABC002XYZ", + "partner_id": self.partner_4.id, + "amount": 270, + "sequence": 1, + } + ) 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_partner': True, - 'match_same_currency': True, - 'match_total_amount': True, - 'match_total_amount_param': 100.0, - 'strict_match_total_amount': True, - # 'match_partner_ids': [ - # (6, 0, [self.partner_3.id, self.partner_4.id]) - # ], - }) + 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_partner": True, + "match_same_currency": True, + "match_total_amount": True, + "match_total_amount_param": 100.0, + "strict_match_total_amount": True, + # 'match_partner_ids': [ + # (6, 0, [self.partner_3.id, self.partner_4.id]) + # ], + } + ) - self._check_statement_matching(my_rule, { - self.bank_line_3.id: {'aml_ids': []}, - self.bank_line_4.id: {'aml_ids': []}, - }, statements=self.bank_st_2) + self._check_statement_matching( + my_rule, + { + self.bank_line_3.id: {"aml_ids": []}, + self.bank_line_4.id: {"aml_ids": []}, + }, + statements=self.bank_st_2, + ) def test_auto_reconcile_strict_match_80(self): - my_rule = self.env['account.reconcile.model'].create({ - 'name': 'Strict Invoice matching amount 80%', - 'rule_type': 'invoice_matching', - 'auto_reconcile': True, - 'match_nature': 'both', - 'match_partner': True, - 'match_same_currency': True, - 'match_total_amount': True, - 'match_total_amount_param': 80.0, - 'strict_match_total_amount': True, - # 'match_partner_ids': [ - # (6, 0, [self.partner_3.id, self.partner_4.id]) - # ], - }) + my_rule = self.env["account.reconcile.model"].create( + { + "name": "Strict Invoice matching amount 80%", + "rule_type": "invoice_matching", + "auto_reconcile": True, + "match_nature": "both", + "match_partner": True, + "match_same_currency": True, + "match_total_amount": True, + "match_total_amount_param": 80.0, + "strict_match_total_amount": True, + # 'match_partner_ids': [ + # (6, 0, [self.partner_3.id, self.partner_4.id]) + # ], + } + ) - self._check_statement_matching(my_rule, { - self.bank_line_3.id: {'aml_ids': []}, - self.bank_line_4.id: {'aml_ids': [self.invoice_line_6.id], 'model': my_rule, 'status': 'reconciled'}, - }, statements=self.bank_st_2) + self._check_statement_matching( + my_rule, + { + self.bank_line_3.id: {"aml_ids": []}, + self.bank_line_4.id: { + "aml_ids": [self.invoice_line_6.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 index 33fd273b..6ee06211 100644 --- a/account_reconcile_model_strict_match_amount/views/account_reconcile_model.xml +++ b/account_reconcile_model_strict_match_amount/views/account_reconcile_model.xml @@ -1,4 +1,4 @@ - + account.reconcile.model.form @@ -6,10 +6,18 @@ - + - - {'invisible': ['|', '|', ('rule_type', '!=', 'invoice_matching'), ('match_total_amount', '=', False), ('strict_match_total_amount', '=', True)]} + + {'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, +) From 7a873632f83f8d3b35201261bb44996fc723109c Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Wed, 29 Apr 2020 15:05:09 +0200 Subject: [PATCH 3/3] [MIG] account_reconcile_model_strict_match_amount: Migration to 13.0 --- .../__manifest__.py | 6 +- .../models/account_reconcile_model.py | 64 ++++++++--- ...unt_reconcile_model_strict_match_amount.py | 107 +++++++++++------- .../views/account_reconcile_model.xml | 2 +- 4 files changed, 120 insertions(+), 59 deletions(-) diff --git a/account_reconcile_model_strict_match_amount/__manifest__.py b/account_reconcile_model_strict_match_amount/__manifest__.py index c3c7b495..b5ed811d 100644 --- a/account_reconcile_model_strict_match_amount/__manifest__.py +++ b/account_reconcile_model_strict_match_amount/__manifest__.py @@ -3,13 +3,13 @@ { "name": "Account Reconciliation Model Strict Match Amount", "summary": "Restrict reconciliation propositions to matching amount parameter", - "version": "12.0.1.0.0", + "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",], + "depends": ["account"], + "data": ["views/account_reconcile_model.xml"], } 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 index 8bb38216..16e1a17d 100644 --- a/account_reconcile_model_strict_match_amount/models/account_reconcile_model.py +++ b/account_reconcile_model_strict_match_amount/models/account_reconcile_model.py @@ -1,6 +1,6 @@ # Copyright 2020 Camptocamp SA # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) -from odoo import api, fields, models +from odoo import fields, models class AccountReconcileModel(models.Model): @@ -13,26 +13,36 @@ class AccountReconcileModel(models.Model): "statement line communication matching exactly existing entries.", ) - @api.multi + # 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: - regexp = r"'[^0-9|^\s]', '', 'g'), '\S(?:.*\S)*'), '\s+'" return r""" - -- Determine a matching or not with the statement line communication using the move.name or move.ref. - -- only digits are considered and reference are split by any space characters + -- Determine a matching or not with the statement line communication using the aml.name, move.name or move.ref. COALESCE( - regexp_split_to_array(substring(REGEXP_REPLACE(move.name, {regexp}) - && regexp_split_to_array(substring(REGEXP_REPLACE(st_line.name, {regexp}) - OR - ( - move.ref IS NOT NULL - AND - regexp_split_to_array(substring(REGEXP_REPLACE(move.ref, {regexp}) - && - regexp_split_to_array(substring(REGEXP_REPLACE(st_line.name, {regexp}) - ), FALSE) + ( + 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 @@ -40,5 +50,27 @@ class AccountReconcileModel(models.Model): ELSE 100 END >= {match_total_amount_param} AS communication_flag """.format( - regexp=regexp, match_total_amount_param=self.match_total_amount_param + 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/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 index ca7f5d8a..c9582be6 100644 --- 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 @@ -6,39 +6,62 @@ from odoo.addons.account.tests.test_reconciliation_matching_rules import ( class TestAccountReconcileModelStrictMatchAmount(TestReconciliationMatchingRules): - def setUp(self): - super().setUp() - self.partner_3 = self.env["res.partner"].create({"name": "partner_3"}) - self.partner_4 = self.env["res.partner"].create({"name": "partner_4"}) - self.invoice_line_5 = self._create_invoice_line( - 150, self.partner_3, "out_invoice" - ) - self.invoice_line_5.ref = "ABC001XYZ" - self.invoice_line_6 = self._create_invoice_line( - 300, self.partner_4, "out_invoice" - ) - self.invoice_line_6.name = "ABC002XYZ" - - self.bank_st_2 = self.env["account.bank.statement"].create( - {"name": "test bank journal 2", "journal_id": self.bank_journal.id,} - ) - - self.bank_line_3 = self.env["account.bank.statement.line"].create( + @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( { - "statement_id": self.bank_st_2.id, + "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": self.partner_3.id, - "amount": 70, + "partner_id": cls.partner_3.id, + "amount": 135, "sequence": 1, } ) - self.bank_line_4 = self.env["account.bank.statement.line"].create( + cls.bank_line_4 = cls.env["account.bank.statement.line"].create( { - "statement_id": self.bank_st_2.id, + "statement_id": cls.bank_st_2.id, "name": "ABC002XYZ", - "partner_id": self.partner_4.id, + "partner_id": cls.partner_4.id, "amount": 270, - "sequence": 1, + "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, } ) @@ -49,53 +72,59 @@ class TestAccountReconcileModelStrictMatchAmount(TestReconciliationMatchingRules "rule_type": "invoice_matching", "auto_reconcile": True, "match_nature": "both", - "match_partner": True, "match_same_currency": True, "match_total_amount": True, "match_total_amount_param": 100.0, "strict_match_total_amount": True, - # 'match_partner_ids': [ - # (6, 0, [self.partner_3.id, self.partner_4.id]) - # ], } ) - 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_80(self): + def test_auto_reconcile_strict_match_90(self): my_rule = self.env["account.reconcile.model"].create( { - "name": "Strict Invoice matching amount 80%", + "name": "Strict Invoice matching amount 90%", "rule_type": "invoice_matching", "auto_reconcile": True, "match_nature": "both", - "match_partner": True, "match_same_currency": True, "match_total_amount": True, - "match_total_amount_param": 80.0, + "match_total_amount_param": 90.0, "strict_match_total_amount": True, - # 'match_partner_ids': [ - # (6, 0, [self.partner_3.id, self.partner_4.id]) - # ], } ) - self._check_statement_matching( my_rule, { - self.bank_line_3.id: {"aml_ids": []}, + 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 index 6ee06211..a55833fe 100644 --- a/account_reconcile_model_strict_match_amount/views/account_reconcile_model.xml +++ b/account_reconcile_model_strict_match_amount/views/account_reconcile_model.xml @@ -12,7 +12,7 @@ />