Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] account_invoice_mass_sending: retry on server disconnect #1855

Draft
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion account_invoice_mass_sending/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from smtplib import SMTPServerDisconnected

from odoo import _, fields, models

from odoo.addons.queue_job.exception import RetryableJobError


class AccountInvoice(models.Model):
_inherit = "account.move"
Expand Down Expand Up @@ -66,4 +70,8 @@ def _send_invoice_individually(self, template=None):
"sending_in_progress": False,
}
)
return wiz.send_and_print_action()
try:
return wiz.send_and_print_action()
except SMTPServerDisconnected as err:
self.sending_in_progress = True
raise RetryableJobError("SMTP server disconnected") from err
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from smtplib import SMTPServerDisconnected

from odoo.tests import TransactionCase
from odoo.tests import TransactionCase, patch

from odoo.addons.queue_job.exception import RetryableJobError
from odoo.addons.queue_job.tests.common import trap_jobs


Expand Down Expand Up @@ -161,3 +163,34 @@ def test_invoice_mass_sending_3(self):
)
trap.perform_enqueued_jobs()
self.assertFalse(self.first_eligible_invoice.sending_in_progress)

@patch(
"odoo.addons.mail.models.mail_mail.MailMail.send",
side_effect=SMTPServerDisconnected("please run connect() first"),
)
def test_gmail_too_many_login_attempts(self, patched_send_email):
"""Test jobs are retried when Gmail is picky about login attempts.

This can happen easily if your SMTP provider is Gmail and you have
tons of invoices to send in parallel. Gmail will not like so many
login attempts and fail with error 454 (see
https://support.google.com/mail/answer/7126229).
"""
with trap_jobs() as trap:
wizard = self.wizard_obj.with_context(
active_ids=self.first_eligible_invoice.ids,
active_model=self.first_eligible_invoice._name,
discard_logo_check=True,
).create({})
wizard.enqueue_invoices()
self.assertTrue(self.first_eligible_invoice.sending_in_progress)
trap.assert_enqueued_job(
self.first_eligible_invoice._send_invoice_individually,
kwargs={"template": self.mail_template_obj},
properties={
"channel": "root.account_invoice_mass_sending_channel",
},
)
trap.assert_jobs_count(1)
with self.assertRaises(RetryableJobError):
trap.perform_enqueued_jobs()
Loading