Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion base_report_to_printer/models/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# Copyright 2024 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
import threading

from odoo import _, api, exceptions, fields, models, registry
from odoo.tools.safe_eval import safe_eval, time

REPORT_TYPES = {"qweb-pdf": "pdf", "qweb-text": "text"}

_logger = logging.getLogger(__name__)


class IrActionsReport(models.Model):
_inherit = "ir.actions.report"
Expand Down Expand Up @@ -143,7 +146,8 @@ def _launch_print_thread():
else:
try:
return self.print_document(record_ids, data=data)
except Exception:
except Exception as e:
_logger.warning("Unable to print document: %s", exc_info=e)
return

def print_document_threaded(self, report_id, record_ids, data):
Expand Down
14 changes: 14 additions & 0 deletions base_report_to_printer/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ def new_printer(self):
}
)

def test_print_document_action_exception_warning(self):
"""Check the exception warning in logs"""
self.report.property_printing_action_id.action_type = "server"
self.report.printing_printer_id = self.new_printer()
with mock.patch(
"odoo.addons.base_report_to_printer.models."
"ir_actions_report.IrActionsReport."
"print_document"
) as print_document:
print_document.side_effect = Exception("error")
with self.assertLogs(level="WARNING"):
self.report.print_document_client_action(self.partners.ids)
print_document.assert_called_once()

def test_can_print_report_context_skip(self):
"""It should return False based on context"""
rec_id = self.new_record().with_context(must_skip_send_to_printer=True)
Expand Down