diff --git a/addons/account/tests/test_account_move_send.py b/addons/account/tests/test_account_move_send.py
index 4361ab0096a..32d489b4140 100644
--- a/addons/account/tests/test_account_move_send.py
+++ b/addons/account/tests/test_account_move_send.py
@@ -466,17 +466,6 @@ class TestAccountMoveSendCommon(AccountTestInvoicingCommon):
@tagged('post_install_l10n', 'post_install', '-at_install')
class TestAccountMoveSend(TestAccountMoveSendCommon):
- def test_send_mail_warning_message(self):
- invoice = self.init_invoice("out_invoice", amounts=[1000], post=True)
- self.partner_a.email = None
- wizard = self.create_send_and_print(invoice)
- self.assertTrue(wizard.send_mail_warning_message)
-
- # Fix the partner.
- self.partner_a.email = "turlututu@tsointsoin"
- wizard.invalidate_recordset(fnames=['send_mail_warning_message'])
- self.assertFalse(wizard.send_mail_warning_message)
-
def test_invoice_single(self):
invoice = self.init_invoice("out_invoice", amounts=[1000], post=True)
wizard = self.create_send_and_print(invoice)
@@ -491,6 +480,7 @@ class TestAccountMoveSend(TestAccountMoveSendCommon):
'mail_lang': 'en_US',
'mail_partner_ids': wizard.move_ids.partner_id.ids,
}])
+ self.assertFalse(wizard.send_mail_warning_message)
self.assertTrue(wizard.mail_subject)
self.assertTrue(wizard.mail_body)
self._assert_mail_attachments_widget(wizard, [{
@@ -536,6 +526,23 @@ class TestAccountMoveSend(TestAccountMoveSendCommon):
])
self.assertFalse(invoice_attachments)
+ def test_invoice_single_readonly_and_checkbox(self):
+ invoice = self.init_invoice("out_invoice", amounts=[1000], post=True)
+
+ self.partner_a.email = None
+ wizard = self.create_send_and_print(invoice)
+ self.assertRecordValues(wizard, [{
+ 'send_mail_readonly': True,
+ 'checkbox_send_mail': False,
+ }])
+
+ self.partner_a.email = "turlututu@tsointsoin"
+ wizard = self.create_send_and_print(invoice)
+ self.assertRecordValues(wizard, [{
+ 'send_mail_readonly': False,
+ 'checkbox_send_mail': True,
+ }])
+
def test_invoice_multi(self):
invoice1 = self.init_invoice("out_invoice", partner=self.partner_a, amounts=[1000], post=True)
invoice2 = self.init_invoice("out_invoice", partner=self.partner_b, amounts=[1000], post=True)
@@ -612,6 +619,35 @@ class TestAccountMoveSend(TestAccountMoveSendCommon):
])
self.assertEqual(len(invoice_attachments), 1)
+ def test_invoice_multi_readonly_checkbox_warning_message(self):
+ invoice1 = self.init_invoice("out_invoice", partner=self.partner_a, amounts=[1000], post=True)
+ invoice2 = self.init_invoice("out_invoice", partner=self.partner_b, amounts=[1000], post=True)
+
+ self.partner_a.email = None
+ self.partner_b.email = None
+ wizard = self.create_send_and_print(invoice1 + invoice2)
+ self.assertFalse(wizard.send_mail_warning_message)
+ self.assertRecordValues(wizard, [{
+ 'send_mail_readonly': True,
+ 'checkbox_send_mail': False,
+ }])
+
+ self.partner_a.email = "turlututu@tsointsoin"
+ wizard = self.create_send_and_print(invoice1 + invoice2)
+ self.assertTrue(wizard.send_mail_warning_message)
+ self.assertRecordValues(wizard, [{
+ 'send_mail_readonly': False,
+ 'checkbox_send_mail': True,
+ }])
+
+ self.partner_b.email = "turlututu@tsointsoin"
+ wizard = self.create_send_and_print(invoice1 + invoice2)
+ self.assertFalse(wizard.send_mail_warning_message)
+ self.assertRecordValues(wizard, [{
+ 'send_mail_readonly': False,
+ 'checkbox_send_mail': True,
+ }])
+
def test_invoice_mail_attachments_widget(self):
invoice = 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 31a976257c3..9da5cad15b3 100644
--- a/addons/account/wizard/account_move_send.py
+++ b/addons/account/wizard/account_move_send.py
@@ -185,29 +185,21 @@ class AccountMoveSend(models.Model):
for wizard in self:
wizard.checkbox_download = wizard.enable_download and wizard.company_id.invoice_is_download
- @api.depends('move_ids')
+ @api.depends('mode', 'checkbox_send_mail')
def _compute_send_mail_extra_fields(self):
for wizard in self:
wizard.enable_send_mail = wizard.mode in ('invoice_single', 'invoice_multi')
wizard.display_mail_composer = wizard.mode == 'invoice_single'
- send_mail_readonly = False
+ wizard.send_mail_warning_message = False
- display_messages = []
- if wizard.enable_send_mail:
- invoices_without_mail_data = wizard.move_ids.filtered(lambda x: not x.partner_id.email)
- if invoices_without_mail_data:
- if wizard.mode == 'invoice_multi':
- display_messages.append(_(
- "The following invoice(s) will not be sent by email, because the customers don't have email "
- "address: "
- ))
- display_messages.append(", ".join(invoices_without_mail_data.mapped('name')))
- send_mail_readonly = True
- else:
- display_messages.append(_("Please add an email address for your partner"))
+ invoices_without_mail_data = wizard.move_ids.filtered(lambda x: not x.partner_id.email)
+ wizard.send_mail_readonly = invoices_without_mail_data == wizard.move_ids
- wizard.send_mail_readonly = send_mail_readonly
- wizard.send_mail_warning_message = "".join(display_messages) if display_messages else None
+ if wizard.mode == 'invoice_multi' and wizard.checkbox_send_mail and invoices_without_mail_data:
+ wizard.send_mail_warning_message = _(
+ "The partners on the following invoices have no email address, "
+ "so those invoices will not be sent: %s"
+ ) % ", ".join(invoices_without_mail_data.mapped('name'))
@api.depends('move_ids')
def _compute_checkbox_send_mail(self):
@@ -635,7 +627,7 @@ class AccountMoveSend(models.Model):
self._generate_invoice_fallback_documents(errors)
# Send mail.
- success = {move: move_data for move, move_data in moves_data.items() if not move_data.get('error')}
+ success = {move: move_data for move, move_data in moves_data.items() if not move_data.get('error') and move.partner_id.email}
if success:
self._hook_if_success(success, from_cron=from_cron, allow_fallback_pdf=allow_fallback_pdf)
diff --git a/addons/account/wizard/account_move_send_views.xml b/addons/account/wizard/account_move_send_views.xml
index 3d3b1655ac7..ceb89bf38e0 100644
--- a/addons/account/wizard/account_move_send_views.xml
+++ b/addons/account/wizard/account_move_send_views.xml
@@ -17,6 +17,16 @@