[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 <smetl@users.noreply.github.com>
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user