diff --git a/addons/account/tests/test_account_move_send.py b/addons/account/tests/test_account_move_send.py index 2566b6bdb05..12799885fee 100644 --- a/addons/account/tests/test_account_move_send.py +++ b/addons/account/tests/test_account_move_send.py @@ -938,3 +938,13 @@ class TestAccountMoveSend(TestAccountMoveSendCommon): wizard.action_send_and_print(allow_fallback_pdf=True) message = self.env['mail.message'].search([('model', '=', invoice._name), ('res_id', '=', invoice.id)], limit=1) self.assertRecordValues(message, [{'subject': custom_subject}]) + + 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) + invoice_draft = self.init_invoice("out_invoice", amounts=[1000], post=False) + + with self.assertRaises(UserError): + self.create_send_and_print(invoice_draft) + with self.assertRaises(UserError): + self.create_send_and_print(invoice_posted + invoice_draft) diff --git a/addons/account/wizard/account_move_send.py b/addons/account/wizard/account_move_send.py index 36cbd5987e8..4c61ee96cb5 100644 --- a/addons/account/wizard/account_move_send.py +++ b/addons/account/wizard/account_move_send.py @@ -85,7 +85,10 @@ class AccountMoveSend(models.Model): results = super().default_get(fields_list) if 'move_ids' in fields_list and 'move_ids' not in results: - results['move_ids'] = [Command.set(self._context.get('active_ids', []))] + move_ids = self._context.get('active_ids', []) + if any(move.state == 'draft' for move in self.env['account.move'].browse(move_ids)): + raise UserError(_("You can't Send & Print invoice(s) in draft state.")) + results['move_ids'] = [Command.set(move_ids)] return results