From 0f2d151d9b96b971869d8ecc4e43adf0bd763dd0 Mon Sep 17 00:00:00 2001 From: oco-odoo Date: Mon, 13 Sep 2021 12:20:52 +0000 Subject: [PATCH] [FIX] account: Don't generate pdf at all when trying to print a misc operation from the 'print invoices' actions Before, clicking on 'print invoices' or 'print invoices without payment' on a posted misc operation raised an error message saying that only invoices could be printed. However, the pdf file still got generated and could be found as attachement on the move. With this commit, we don't generate the file anymore in this case. closes odoo/odoo#76534 X-original-commit: 4c06b3c1180048b1c0db5067adf0c0bef5c02785 Signed-off-by: Laurent Smet --- addons/account/models/account_move.py | 2 -- addons/account/models/ir_actions_report.py | 12 ++++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index f6b396f2165..ce01650f691 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3195,8 +3195,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 27deaa9fe7e..f13f65e7301 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)