diff --git a/base_report_to_printer/README.rst b/base_report_to_printer/README.rst index 9d20b9a5fc4..40f09e8e41a 100644 --- a/base_report_to_printer/README.rst +++ b/base_report_to_printer/README.rst @@ -161,6 +161,10 @@ Contributors * Matias Peralta * Akim Juillerat +* `Tecnativa `_: + + * Sergio Teruel + Maintainers ~~~~~~~~~~~ diff --git a/base_report_to_printer/models/ir_actions_report.py b/base_report_to_printer/models/ir_actions_report.py index 0c458372815..af2cdf5f4b7 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"} @@ -118,6 +120,29 @@ 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: + return self.print_document(record_ids, data=data) + + 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) diff --git a/base_report_to_printer/models/printing_printer.py b/base_report_to_printer/models/printing_printer.py index f6af23031df..3042d3342c3 100644 --- a/base_report_to_printer/models/printing_printer.py +++ b/base_report_to_printer/models/printing_printer.py @@ -66,6 +66,7 @@ class PrintingPrinter(models.Model): tray_ids = fields.One2many( comodel_name="printing.tray", inverse_name="printer_id", string="Paper Sources" ) + multi_thread = fields.Boolean() def _prepare_update_from_cups(self, cups_connection, cups_printer): mapping = {3: "available", 4: "printing", 5: "error"} diff --git a/base_report_to_printer/readme/CONTRIBUTORS.rst b/base_report_to_printer/readme/CONTRIBUTORS.rst index a046d905596..0070def1fc8 100644 --- a/base_report_to_printer/readme/CONTRIBUTORS.rst +++ b/base_report_to_printer/readme/CONTRIBUTORS.rst @@ -13,3 +13,7 @@ * Alexandre Fayolle * Matias Peralta * Akim Juillerat + +* `Tecnativa `_: + + * Sergio Teruel diff --git a/base_report_to_printer/static/description/index.html b/base_report_to_printer/static/description/index.html index 98ebb98e25d..6bef3bbdbac 100644 --- a/base_report_to_printer/static/description/index.html +++ b/base_report_to_printer/static/description/index.html @@ -8,11 +8,10 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ +:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. -Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +274,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: gray; } /* line numbers */ +pre.code .ln { color: grey; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +300,7 @@ span.pre { white-space: pre } -span.problematic, pre.problematic { +span.problematic { color: red } span.section-subtitle { @@ -510,14 +509,16 @@

Contributors

  • Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
  • Matias Peralta <mnp@adhoc.com.ar>
  • Akim Juillerat <akim.juillerat@camptocamp.com>
  • +
  • Tecnativa:
      +
    • Sergio Teruel
    • +
    +
  • Maintainers

    This module is maintained by the OCA.

    - -Odoo Community Association - +Odoo Community Association

    OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

    diff --git a/base_report_to_printer/static/src/js/qweb_action_manager.esm.js b/base_report_to_printer/static/src/js/qweb_action_manager.esm.js index 79ea69f24fb..f6245fdf5ba 100644 --- a/base_report_to_printer/static/src/js/qweb_action_manager.esm.js +++ b/base_report_to_printer/static/src/js/qweb_action_manager.esm.js @@ -15,11 +15,11 @@ async function cupsReportActionHandler(action, options, env) { print_action.action === "server" && !print_action.printer_exception ) { - const result = await orm.call("ir.actions.report", "print_document", [ - action.id, - action.context.active_ids, - action.data, - ]); + const result = await orm.call( + "ir.actions.report", + "print_document_client_action", + [action.id, action.context.active_ids, action.data] + ); if (result) { env.services.notification.add(env._t("Successfully sent to printer!"), { type: "success", diff --git a/base_report_to_printer/tests/test_ir_actions_report.py b/base_report_to_printer/tests/test_ir_actions_report.py index e010dd883c5..61fd527f50e 100644 --- a/base_report_to_printer/tests/test_ir_actions_report.py +++ b/base_report_to_printer/tests/test_ir_actions_report.py @@ -295,3 +295,20 @@ def test_onchange_printer_tray_id_not_empty(self): self.assertEqual(action.printer_tray_id, tray) action.onchange_printing_printer_id() self.assertFalse(action.printer_tray_id) + + def test_print_in_new_thread(self): + """It should return the action and printer from printing action in other thread""" + report = self.Model.search([], limit=1) + self.env.user.printing_action = "server" + printing_action = self.new_printing_action() + printing_action.user_id = self.env.user + printing_action.printer_id = self.new_printer() + printing_action.printer_id.multi_thread = True + self.assertEqual( + report.behaviour(), + { + "action": printing_action.action, + "printer": printing_action.printer_id, + "tray": False, + }, + ) diff --git a/base_report_to_printer/views/printing_printer.xml b/base_report_to_printer/views/printing_printer.xml index 5c7657c0688..dcc5dfed476 100644 --- a/base_report_to_printer/views/printing_printer.xml +++ b/base_report_to_printer/views/printing_printer.xml @@ -76,6 +76,7 @@ +