[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) <las@odoo.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
</group>
|
||||
<group>
|
||||
<field name="mail_template_id"
|
||||
required="mode == 'invoice_multi'"
|
||||
options="{'no_create': True, 'no_edit': True}"
|
||||
context="{'default_model': 'account.move'}"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user