diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 5c35df2c3c585c113144e9f35cf9dafcd0c2aa3d..60d7c3ca2b7f53054f22b628ca5b0112ddf1bb8c 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2854,8 +2854,6 @@ class AccountMove(models.Model): move.write({'invoice_line_ids' : new_invoice_line_ids}) def _get_report_base_filename(self): - if any(not move.is_invoice() for move in self): - raise UserError(_("Only invoices could be printed.")) return self._get_move_display_name() def _get_name_invoice_report(self): diff --git a/addons/account/models/ir_actions_report.py b/addons/account/models/ir_actions_report.py index 27deaa9fe7e2865a23d02bda43a428973f0c1a19..f13f65e73012c77f901f5b19b36ecb04f1dfa06b 100644 --- a/addons/account/models/ir_actions_report.py +++ b/addons/account/models/ir_actions_report.py @@ -33,3 +33,15 @@ class IrActionsReport(models.Model): if attachment: attachment.register_as_main_attachment(force=False) return res + + def render_qweb_pdf(self, res_ids=None, data=None): + # Overridden so that the print > invoices actions raises an error + # when trying to print a miscellaneous operation instead of an invoice. + if self.model == 'account.move' and res_ids: + invoice_reports = (self.env.ref('account.account_invoices_without_payment'), self.env.ref('account.account_invoices')) + if self in invoice_reports: + moves = self.env['account.move'].browse(res_ids) + if any(not move.is_invoice(include_receipts=True) for move in moves): + raise UserError(_("Only invoices could be printed.")) + + return super().render_qweb_pdf(res_ids=res_ids, data=None)