From 37689b189ee904497eb0ce0097ecf013cac1a91c Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Tue, 12 Mar 2019 14:17:36 +0000 Subject: [PATCH] [FIX] payment: do not retry indefinitely to post process transactions Suppose that a payment transaction cannot be reconciled for any reason. Then _cron_post_process_after_done will try to process it every 10 minutes until the end of time. Moreover, if the user takes some manual action before _cron_post_process_after_done, even if in principle it would have been able to go through, then it is likely to fail, e.g. on invoice_open. Meaning that a transaction that could have been processed will become an undead transaction. To avoid that situation we set an arbitrary retry_limit_date set to 2 days, which seems a reasonnable compromise. It gives some time for the transaction to go through, but not exaggeratedly so. opw 1945953 closes odoo/odoo#31791 Signed-off-by: Toufik Benjaa (tbe) --- addons/payment/models/payment_acquirer.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 209c4556d7b..bcfcb2025bf 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -785,10 +785,13 @@ class PaymentTransaction(models.Model): def _cron_post_process_after_done(self): if not self: ten_minutes_ago = datetime.now() - relativedelta.relativedelta(minutes=10) + # we don't want to forever try to process a transaction that doesn't go through + retry_limit_date = datetime.now() - relativedelta.relativedelta(days=2) # we retrieve all the payment tx that need to be post processed self = self.search([('state', '=', 'done'), ('is_processed', '=', False), ('date', '<=', ten_minutes_ago), + ('date', '>=', retry_limit_date), ]) for tx in self: try: