From 1c7dd1f01eb22e07bf40b5ea4f69c9643835a1ca Mon Sep 17 00:00:00 2001 From: "Claire Bretton (clbr)" Date: Fri, 6 Oct 2023 17:01:48 +0200 Subject: [PATCH] [FIX] account: Send & Print should not be used on draft invoices The Send/Send & Print button is accessible in list view, the wizard should raise an error if it is opened with invoices in "draft" state. closes odoo/odoo#138311 X-original-commit: cbc0972bb3eaddf88131b0153f364d1a65d0a968 Signed-off-by: Laurent Smet (las) Signed-off-by: Claire Bretton (clbr) --- addons/account/tests/test_account_move_send.py | 10 ++++++++++ addons/account/wizard/account_move_send.py | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) 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