[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) <las@odoo.com>
Signed-off-by: Claire Bretton (clbr) <clbr@odoo.com>
This commit is contained in:
Claire Bretton (clbr)
2023-10-11 08:18:56 +00:00
parent 52653a9d05
commit 1c7dd1f01e
2 changed files with 14 additions and 1 deletions
@@ -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)
+4 -1
View File
@@ -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