Skip to content

Commit

Permalink
[IMP] base_report_to_printer: avoid printing if printer is not active
Browse files Browse the repository at this point in the history
  • Loading branch information
micheledic authored Oct 10, 2024
1 parent c199434 commit e91ef7e
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions base_report_to_printer/models/printing_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,23 @@ def print_options(self, report=None, **print_opts):
def print_file(self, file_name, report=None, **print_opts):
"""Print a file"""
self.ensure_one()
title = print_opts.pop("title", file_name)
connection = self.server_id._open_connection(raise_on_error=True)
options = self.print_options(report=report, **print_opts)

_logger.debug(
"Sending job to CUPS printer %s on %s with options %s"
% (self.system_name, self.server_id.address, options)
)
connection.printFile(self.system_name, file_name, title, options=options)
_logger.info(
"Printing job: '{}' on {}".format(file_name, self.server_id.address)
)
try:
os.remove(file_name)
except OSError as exc:
_logger.warning("Unable to remove temporary file %s: %s", file_name, exc)
if self.active:
title = print_opts.pop("title", file_name)
connection = self.server_id._open_connection(raise_on_error=True)
options = self.print_options(report=report, **print_opts)

_logger.debug(
"Sending job to CUPS printer %s on %s with options %s"
% (self.system_name, self.server_id.address, options)
)
connection.printFile(self.system_name, file_name, title, options=options)
_logger.info(
"Printing job: '{}' on {}".format(file_name, self.server_id.address)
)
try:
os.remove(file_name)
except OSError as exc:
_logger.warning("Unable to remove temporary file %s: %s", file_name, exc)
return True

def set_default(self):
Expand Down

0 comments on commit e91ef7e

Please sign in to comment.