From 489faccb788a643dc0e2908bd299bdd93ae2bff0 Mon Sep 17 00:00:00 2001 From: "Claire Bretton (clbr)" Date: Tue, 24 Oct 2023 15:17:10 +0200 Subject: [PATCH] [FIX] account: Send & Print - prevent multi email if no mail template set We don't want to allow to send multiple invoices by email if there is no mail template set. It would lead to unwanted behaviors. closes odoo/odoo#139612 Related: odoo/enterprise#49477 Signed-off-by: Laurent Smet (las) --- addons/account/tests/test_account_move_send.py | 16 ++++++++++++++-- addons/account/wizard/account_move_send.py | 4 ++++ .../account/wizard/account_move_send_views.xml | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/addons/account/tests/test_account_move_send.py b/addons/account/tests/test_account_move_send.py index ef5057bcc51..5021a10665e 100644 --- a/addons/account/tests/test_account_move_send.py +++ b/addons/account/tests/test_account_move_send.py @@ -888,8 +888,8 @@ class TestAccountMoveSend(TestAccountMoveSendCommon): self.assertFalse(invoice.invoice_pdf_report_id) self.assertTrue(invoice.message_main_attachment_id) - def test_with_empty_mail_template(self): - """ Test you can use the send & print wizard without any mail template. """ + def test_with_empty_mail_template_single(self): + """ Test you can use the send & print wizard without any mail template if and only if you are in single mode. """ self.partner_a.email = "turlututu@tsointsoin" invoice = self.init_invoice("out_invoice", amounts=[1000], post=True) @@ -900,6 +900,18 @@ class TestAccountMoveSend(TestAccountMoveSendCommon): message = self.env['mail.message'].search([('model', '=', invoice._name), ('res_id', '=', invoice.id)], limit=1) self.assertRecordValues(message, [{'subject': custom_subject}]) + def test_with_empty_mail_template_multi(self): + """ Test shouldn't be able to send email without mail template in multi mode. """ + self.partner_a.email = "turlututu@tsointsoin" + invoice_1 = self.init_invoice("out_invoice", amounts=[1000], post=True) + invoice_2 = self.init_invoice("out_invoice", amounts=[1000], post=True) + + custom_subject = "turlututu" + wizard = self.create_send_and_print((invoice_1 + invoice_2), mail_template_id=None, mail_subject=custom_subject) + + with self.assertRaises(UserError): + wizard.action_send_and_print(allow_fallback_pdf=True) + def test_with_draft_invoices(self): """ Use Send & Print wizard on draft invoice(s) should raise an error. """ invoice_posted = self.init_invoice("out_invoice", amounts=[1000], post=True) diff --git a/addons/account/wizard/account_move_send.py b/addons/account/wizard/account_move_send.py index 9789afe98da..e4df2e30978 100644 --- a/addons/account/wizard/account_move_send.py +++ b/addons/account/wizard/account_move_send.py @@ -653,6 +653,10 @@ class AccountMoveSend(models.TransientModel): proforma PDF report instead. """ self.ensure_one() + + if self.mode == 'invoice_multi' and self.checkbox_send_mail and not self.mail_template_id: + raise UserError(_('Please select a mail template to send multiple invoices.')) + force_synchronous = force_synchronous or self.checkbox_download process_later = self.mode == 'invoice_multi' and not force_synchronous if process_later: diff --git a/addons/account/wizard/account_move_send_views.xml b/addons/account/wizard/account_move_send_views.xml index 74f18544498..14d9f2ce07d 100644 --- a/addons/account/wizard/account_move_send_views.xml +++ b/addons/account/wizard/account_move_send_views.xml @@ -80,6 +80,7 @@