Skip to content

Commit

Permalink
[FIX] snailmail: avoid resending letters on rollback
Browse files Browse the repository at this point in the history
Up until now, the cron would send letters by batch on a single call with
15 secs timeout which is unfortunately insufficient to have an answer
from the IAP server.
The cron would therefore fail and would end up trying to resend the same
letters again and again even if each call had reached the IAP server and that the
letters were actually processed.

closes odoo#55717

Signed-off-by: Rémi Rahir (rar) <[email protected]>
  • Loading branch information
rrahir committed Aug 11, 2020
1 parent 24055f4 commit 98ec5df
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions addons/snailmail/models/snailmail_letter.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ def _snailmail_print(self):

@api.multi
def snailmail_print(self):
self._snailmail_print()
self.write({'state': 'pending'})
if len(self) == 1:
self._snailmail_print()

@api.multi
def cancel(self):
Expand All @@ -297,10 +299,13 @@ def _snailmail_estimate(self):
return len(self)

@api.model
def _snailmail_cron(self):
def _snailmail_cron(self, autocommit=True):
letters_send = self.search([('state', '=', 'pending')])
if letters_send:
letters_send._snailmail_print()
for letter in letters_send:
letter._snailmail_print()
# Commit after every letter sent to avoid to send it back in case of a rollback
if autocommit:
self.env.cr.commit()
limit_date = datetime.datetime.utcnow() - datetime.timedelta(days=1)
limit_date_str = datetime.datetime.strftime(limit_date, tools.DEFAULT_SERVER_DATETIME_FORMAT)
letters_canceled = self.search([
Expand Down

0 comments on commit 98ec5df

Please sign in to comment.