mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[IMP] base_report_to_printer: out of connection fallback to client
If the CUPS server isn't available the user won't be able to do anything to print the report they need. At last we can give them the chance to have a fallback behavior downloading the document. TT47134
This commit is contained in:
@@ -53,6 +53,10 @@ class IrActionsReport(models.Model):
|
||||
"action": result["action"],
|
||||
"printer_name": result["printer"].name,
|
||||
}
|
||||
if result.get("printer_exception") and not self.env.context.get(
|
||||
"skip_printer_exception"
|
||||
):
|
||||
serializable_result["printer_exception"] = True
|
||||
return serializable_result
|
||||
|
||||
def _get_user_default_print_behaviour(self):
|
||||
@@ -97,6 +101,21 @@ class IrActionsReport(models.Model):
|
||||
# For some reason design takes report defaults over
|
||||
# False action entries so we must allow for that here
|
||||
result.update({k: v for k, v in print_action.behaviour().items() if v})
|
||||
printer = result.get("printer")
|
||||
if printer:
|
||||
# When no printer is available we can fallback to the default behavior
|
||||
# letting the user to manually print the reports.
|
||||
try:
|
||||
printer.server_id._open_connection(raise_on_error=True)
|
||||
printer_exception = printer.status in [
|
||||
"error",
|
||||
"server-error",
|
||||
"unavailable",
|
||||
]
|
||||
except Exception:
|
||||
printer_exception = True
|
||||
if printer_exception and not self.env.context.get("skip_printer_exception"):
|
||||
result["printer_exception"] = True
|
||||
return result
|
||||
|
||||
def print_document(self, record_ids, data=None):
|
||||
@@ -140,7 +159,12 @@ class IrActionsReport(models.Model):
|
||||
"""
|
||||
if self.env.context.get("must_skip_send_to_printer"):
|
||||
return False
|
||||
if behaviour["action"] == "server" and printer and document:
|
||||
if (
|
||||
behaviour["action"] == "server"
|
||||
and printer
|
||||
and document
|
||||
and not behaviour.get("printer_exception")
|
||||
):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user