From 2327aa461dbd068acb409f9ea1cd68fbbdf1fc56 Mon Sep 17 00:00:00 2001 From: "Antoine Vandevenne (anv)" Date: Mon, 14 Jun 2021 08:13:00 +0000 Subject: [PATCH] [IMP] payment: prevent validation transactions from creating payments Before commit 139dd9d, only validation transactions made with a validity check (transfer of a small amount with immediate refund) led to the creation of an `account.payment` record for the reconciliation. As that amount was never perceived, there was in fact nothing to reconcile. With commit 139dd9d, it is possible to make $0-validations (the validity check is handled by the provider). As this feature now sheds light on the flawed behavior described above, it has been decided to entirely stop creating `account.payment` records for validation transactions. This commit thus prevents the post-processing of validation transactions from preparing their reconciliation. task-2494916 closes odoo/odoo#72137 X-original-commit: f460d7a5a995cd7b934d32f82b50aede43efbace Signed-off-by: Victor Feyens (vfe) Signed-off-by: Antoine Vandevenne (anv) --- addons/payment/models/payment_transaction.py | 8 ++++++-- addons/payment/tests/__init__.py | 1 + addons/payment/tests/test_transactions.py | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 addons/payment/tests/test_transactions.py diff --git a/addons/payment/models/payment_transaction.py b/addons/payment/models/payment_transaction.py index 4ba95589546..ad925accf36 100644 --- a/addons/payment/models/payment_transaction.py +++ b/addons/payment/models/payment_transaction.py @@ -797,13 +797,17 @@ class PaymentTransaction(models.Model): def _reconcile_after_done(self): """ Post relevant fiscal documents and create missing payments. + As there is nothing to reconcile for validation transactions, no payment is created for + them. This is also true for validations with a validity check (transfer of a small amount + with immediate refund) because validation amounts are not included in payouts. + :return: None """ # Validate invoices automatically once the transaction is confirmed self.invoice_ids.filtered(lambda inv: inv.state == 'draft').action_post() - # Create and post missing payments - for tx in self.filtered(lambda t: not t.payment_id): + # Create and post missing payments for transactions requiring reconciliation + for tx in self.filtered(lambda t: t.operation != 'validation' and not t.payment_id): tx._create_payment() def _create_payment(self, **extra_create_values): diff --git a/addons/payment/tests/__init__.py b/addons/payment/tests/__init__.py index 394983c6382..9ae472bf3b4 100644 --- a/addons/payment/tests/__init__.py +++ b/addons/payment/tests/__init__.py @@ -5,3 +5,4 @@ from . import http_common from . import multicompany_common from . import test_flows from . import test_multicompany_flows +from . import test_transactions diff --git a/addons/payment/tests/test_transactions.py b/addons/payment/tests/test_transactions.py new file mode 100644 index 00000000000..3bcb97ec4e9 --- /dev/null +++ b/addons/payment/tests/test_transactions.py @@ -0,0 +1,17 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.tests import tagged + +from odoo.addons.payment.tests.common import PaymentCommon + + +@tagged('-at_install', 'post_install') +class TestTransactions(PaymentCommon): + + def test_no_payment_for_validations(self): + tx = self.create_transaction(flow='dummy', operation='validation') # Overwrite the flow + tx._reconcile_after_done() + payment_count = self.env['account.payment'].search_count( + [('payment_transaction_id', '=', tx.id)] + ) + self.assertEqual(payment_count, 0, "validation transactions should not create payments")