mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[IMP] base_report_to_printer: Add printer option to launch reports in new thread
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
|
||||
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
|
||||
# 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 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 @@ class IrActionsReport(models.Model):
|
||||
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)
|
||||
|
||||
@@ -12,7 +12,7 @@ import logging
|
||||
import os
|
||||
from tempfile import mkstemp
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo import api, fields, models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -67,6 +67,14 @@ 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"}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user