[FIX] account: is_being_sent banner is displayed on error

When sending a single invoice, if an error was raised in the middle of the
process we wrongly displayed the banner "This invoice is being sent
in the background".

task-id:3515915

closes odoo/odoo#137571

X-original-commit: 844f9b672b91c50affd783253b2b8ee4b816cef7
Signed-off-by: Laurent Smet (las) <las@odoo.com>
Signed-off-by: Claire Bretton (clbr) <clbr@odoo.com>
This commit is contained in:
Claire Bretton (clbr)
2023-10-04 20:52:45 +00:00
parent b761a873f0
commit 3a18482f63
2 changed files with 39 additions and 4 deletions
+9 -3
View File
@@ -639,7 +639,7 @@ class AccountMove(models.Model):
JOIN account_move_account_move_send_rel move_send_rel
ON move_send_rel.account_move_id in %(move_ids)s
AND send.id = move_send_rel.account_move_send_id
WHERE send.mode != 'done'
WHERE send.mode = 'invoice_multi'
""",
params={'move_ids': tuple(self.ids)}
)
@@ -4116,11 +4116,17 @@ class AccountMove(models.Model):
:param with_commit: Flag indicating a commit should be made between each job.
'''
# Clean already processed wizards.
self.env['account.move.send'].search([('mode', '=', 'done')]).unlink()
self.env['account.move.send'].search([
'|',
('mode', '=', 'done'),
'&',
('mode', '=', 'invoice_single'),
('create_date', '<=', fields.Date.context_today(self) - relativedelta(days=1)),
]).unlink()
# Process.
limit = job_count + 1
to_process = self.env['account.move.send'].search([('mode', '!=', 'done')], limit=limit)
to_process = self.env['account.move.send'].search([('mode', '=', 'invoice_multi')], limit=limit)
need_retrigger = len(to_process) > job_count
+30 -1
View File
@@ -2,9 +2,11 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import date
from dateutil.relativedelta import relativedelta
from freezegun import freeze_time
from unittest.mock import patch
from odoo import Command
from odoo import Command, fields
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.addons.mail.tests.common import MailCommon
from odoo.exceptions import UserError
@@ -829,6 +831,33 @@ class TestAccountMoveSend(TestAccountMoveSendCommon):
self.env.ref('account.ir_cron_account_move_send').method_direct_trigger()
self.assertFalse(wizard.exists())
def test_unlink_wizard_invoice_single(self):
invoice = self.init_invoice("out_invoice", amounts=[1000], post=True)
wizard = self.create_send_and_print(invoice)
def _hook_if_errors(self, moves_data, from_cron=False, allow_fallback_pdf=False):
raise UserError('Test Error')
def _hook_invoice_document_before_pdf_report_render(self, invoice, invoice_data):
invoice_data['error'] = 'test_error'
# Process with an error so that the wizard doesn't reach 'done' state
with (
patch.object(type(wizard), '_hook_if_errors', _hook_if_errors),
patch.object(type(wizard), '_hook_invoice_document_before_pdf_report_render', _hook_invoice_document_before_pdf_report_render)
):
with self.assertRaises(UserError), self.cr.savepoint():
wizard.action_send_and_print(allow_fallback_pdf=False)
# If cron is triggered within the same day wizard is still exists. We don't want to delete an opened wizard.
self.env.ref('account.ir_cron_account_move_send').method_direct_trigger()
self.assertTrue(wizard.exists())
# If cron is triggered one day or later than the creation it should be garbage collected.
with freeze_time(fields.Date.today() + relativedelta(days=1)):
self.env.ref('account.ir_cron_account_move_send').method_direct_trigger()
self.assertFalse(wizard.exists())
def test_with_empty_mail_template(self):
""" Test you can use the send & print wizard without any mail template. """
self.partner_a.email = "turlututu@tsointsoin"