diff --git a/.oca/oca-port/blacklist/base_report_to_printer.json b/.oca/oca-port/blacklist/base_report_to_printer.json new file mode 100644 index 00000000000..9f49464fd77 --- /dev/null +++ b/.oca/oca-port/blacklist/base_report_to_printer.json @@ -0,0 +1,5 @@ +{ + "pull_requests": { + "OCA/report-print-send#275": "It's the migration PR..." + } +} diff --git a/base_report_to_printer/README.rst b/base_report_to_printer/README.rst index 2f191496647..8fc4a22678d 100644 --- a/base_report_to_printer/README.rst +++ b/base_report_to_printer/README.rst @@ -106,6 +106,13 @@ Guidelines for use: When no tray is configured for a report and a user, the default tray setup on the CUPS server is used. +Known issues / Roadmap +====================== + +- With threaded printing there's no download fallback when the issue isn't detected by + the CUPS Odoo backend. To able to do it, we would need to notify the bus or use + web_notify for it. + Changelog ========= @@ -163,6 +170,11 @@ Contributors * Akim Juillerat * Jacques-Etienne Baudoux (BCIM) +* `Tecnativa `_: + + * Sergio Teruel + * David Vidal + Maintainers ~~~~~~~~~~~ diff --git a/base_report_to_printer/__manifest__.py b/base_report_to_printer/__manifest__.py index a399b157ab0..1d8e9d797b1 100644 --- a/base_report_to_printer/__manifest__.py +++ b/base_report_to_printer/__manifest__.py @@ -18,6 +18,7 @@ "data": [ "data/printing_data.xml", "security/security.xml", + "security/ir.model.access.csv", "views/printing_printer.xml", "views/printing_server.xml", "views/printing_job.xml", diff --git a/base_report_to_printer/models/ir_actions_report.py b/base_report_to_printer/models/ir_actions_report.py index 05477092437..8af514383c5 100644 --- a/base_report_to_printer/models/ir_actions_report.py +++ b/base_report_to_printer/models/ir_actions_report.py @@ -3,9 +3,11 @@ # Copyright (C) 2011 Agile Business Group sagl () # Copyright (C) 2011 Domsense srl () # Copyright (C) 2013-2014 Camptocamp () +# Copyright 2024 Tecnativa - Sergio Teruel # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import threading -from odoo import _, api, exceptions, fields, models +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"} @@ -57,6 +59,8 @@ def print_action_for_report_name(self, report_name): "skip_printer_exception" ): serializable_result["printer_exception"] = True + if self.env.context.get("force_print_to_client"): + serializable_result["action"] = "client" return serializable_result def _get_user_default_print_behaviour(self): @@ -118,6 +122,32 @@ def behaviour(self): result["printer_exception"] = True return result + def print_document_client_action(self, record_ids, data=None): + behaviour = self.behaviour() + printer = behaviour.pop("printer", None) + if printer.multi_thread: + + @self.env.cr.postcommit.add + def _launch_print_thread(): + threaded_calculation = threading.Thread( + target=self.print_document_threaded, + args=(self.id, record_ids, data), + ) + threaded_calculation.start() + + return True + else: + try: + return self.print_document(record_ids, data=data) + except Exception: + return + + def print_document_threaded(self, report_id, record_ids, data): + with registry(self._cr.dbname).cursor() as cr: + self = self.with_env(self.env(cr=cr)) + report = self.env["ir.actions.report"].browse(report_id) + report.print_document(record_ids, data) + def print_document(self, record_ids, data=None): """Print a document, do not return the document file""" report_type = REPORT_TYPES.get(self.report_type) @@ -146,6 +176,7 @@ def print_document(self, record_ids, data=None): else: title = self.report_name behaviour["title"] = title + behaviour["res_ids"] = record_ids # TODO should we use doc_format instead of report_type return printer.print_document( self, document, doc_format=self.report_type, **behaviour diff --git a/base_report_to_printer/models/printing_printer.py b/base_report_to_printer/models/printing_printer.py index dec7605d7c8..efd04e0d003 100644 --- a/base_report_to_printer/models/printing_printer.py +++ b/base_report_to_printer/models/printing_printer.py @@ -12,7 +12,7 @@ import os from tempfile import mkstemp -from odoo import fields, models +from odoo import api, fields, models _logger = logging.getLogger(__name__) @@ -67,11 +67,19 @@ class PrintingPrinter(models.Model): tray_ids = fields.One2many( comodel_name="printing.tray", inverse_name="printer_id", string="Paper Sources" ) + multi_thread = fields.Boolean( + compute="_compute_multi_thread", readonly=False, store=True + ) + + @api.depends("server_id.multi_thread") + def _compute_multi_thread(self): + for printer in self: + printer.multi_thread = printer.server_id.multi_thread def _prepare_update_from_cups(self, cups_connection, cups_printer): mapping = {3: "available", 4: "printing", 5: "error"} cups_vals = { - "name": cups_printer["printer-info"], + "name": self.name or cups_printer["printer-info"], "model": cups_printer.get("printer-make-and-model", False), "location": cups_printer.get("printer-location", False), "uri": cups_printer.get("device-uri", False), diff --git a/base_report_to_printer/models/printing_server.py b/base_report_to_printer/models/printing_server.py index 06de8faf474..013587089e6 100644 --- a/base_report_to_printer/models/printing_server.py +++ b/base_report_to_printer/models/printing_server.py @@ -42,6 +42,7 @@ class PrintingServer(models.Model): string="Printers List", help="List of printers available on this server.", ) + multi_thread = fields.Boolean() def _open_connection(self, raise_on_error=False): self.ensure_one() @@ -121,6 +122,11 @@ def update_printers(self, domain=None, raise_on_error=False): printer_values["server_id"] = server.id updated_printers.append(name) + # We want to keep any existing customized name over existing printer + # We want also to rely in the system name as a fallback to avoid + # empty names. + if not printer_values.get("name") and not printer.name: + printer_values["name"] = name if not printer: printer_values["system_name"] = name printer.create(printer_values) diff --git a/base_report_to_printer/readme/CONTRIBUTORS.rst b/base_report_to_printer/readme/CONTRIBUTORS.rst index 4626c55e6b1..3223d01c7b9 100644 --- a/base_report_to_printer/readme/CONTRIBUTORS.rst +++ b/base_report_to_printer/readme/CONTRIBUTORS.rst @@ -15,3 +15,8 @@ * Hughes Damry * Akim Juillerat * Jacques-Etienne Baudoux (BCIM) + +* `Tecnativa `_: + + * Sergio Teruel + * David Vidal diff --git a/base_report_to_printer/readme/ROADMAP.rst b/base_report_to_printer/readme/ROADMAP.rst new file mode 100644 index 00000000000..a7b6610b4d7 --- /dev/null +++ b/base_report_to_printer/readme/ROADMAP.rst @@ -0,0 +1,3 @@ +- With threaded printing there's no download fallback when the issue isn't detected by + the CUPS Odoo backend. To able to do it, we would need to notify the bus or use + web_notify for it. diff --git a/base_report_to_printer/security/ir.model.access.csv b/base_report_to_printer/security/ir.model.access.csv new file mode 100644 index 00000000000..b97fc91290e --- /dev/null +++ b/base_report_to_printer/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_printing_printer_update_wizard,printers update,model_printing_printer_update_wizard,base.group_system,1,1,1,1 diff --git a/base_report_to_printer/static/description/index.html b/base_report_to_printer/static/description/index.html index 431a96b441f..741565aa692 100644 --- a/base_report_to_printer/static/description/index.html +++ b/base_report_to_printer/static/description/index.html @@ -396,16 +396,17 @@

Report to printer

  • Installation
  • Configuration
  • Usage
  • -
  • Changelog