Skip to content

Commit

Permalink
Merge PR #381 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Nov 18, 2024
2 parents ab0e7d3 + 5b5444f commit fc386a1
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 58 deletions.
12 changes: 9 additions & 3 deletions base_report_to_printer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ this will not be displayed by CUPS web interface or in Odoo. To see this
information, you need to change the configuration of your CUPS server
and set the JobPrivateValue directive to "none" (or some other list of
values which does not include "job-name") , and reload the server. See
cupsd.conf(5)
<`https://www.cups.org/doc/man-cupsd.conf.html\\> <https://www.cups.org/doc/man-cupsd.conf.html\>>`__
for details.
cupsd.conf(5) <https://www.cups.org/doc/man-cupsd.conf.html> for
details.

Usage
=====
Expand All @@ -112,6 +111,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
=========

Expand Down
1 change: 1 addition & 0 deletions base_report_to_printer/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion base_report_to_printer/i18n/sv.po
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ msgstr "Guide"
#: code:addons/base_report_to_printer/wizards/print_attachment_report.py:0
#, python-format
msgid "{name} ({copies} copies)"
msgstr "{namn} ({kopior} kopior)"
msgstr "{name} ({copies} kopior)"

#~ msgid "Job"
#~ msgstr "Jobb"
Expand Down
59 changes: 57 additions & 2 deletions base_report_to_printer/models/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -53,6 +55,12 @@ def print_action_for_report_name(self, report_name):
"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
if self.env.context.get("force_print_to_client"):
serializable_result["action"] = "client"
return serializable_result

def _get_user_default_print_behaviour(self):
Expand Down Expand Up @@ -97,8 +105,49 @@ def behaviour(self):
# 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_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)
Expand Down Expand Up @@ -127,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
Expand All @@ -140,7 +190,12 @@ def _can_print_report(self, behaviour, printer, document):
"""
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

Expand Down
12 changes: 8 additions & 4 deletions base_report_to_printer/models/printing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PrintingJob(models.Model):

name = fields.Char(help="Job name.")
active = fields.Boolean(
default=True, help="Unchecked if the job is purged from cups."
default=True, help="Unchecked if the job is purged from CUPS."
)
job_id_cups = fields.Integer(
string="Job ID", required=True, help="CUPS id for this job."
Expand All @@ -40,11 +40,15 @@ class PrintingJob(models.Model):
help="Percentage of progress for this job.",
)
time_at_creation = fields.Datetime(
required=True, help="Date and time of creation for this job."
string="Creation Date",
required=True,
help="Date and time of creation of this job.",
)
time_at_processing = fields.Datetime(
string="Processing Date", help="Date and time of process for this job."
)
time_at_processing = fields.Datetime(help="Date and time of process for this job.")
time_at_completed = fields.Datetime(
help="Date and time of completion for this job."
string="Completion Date", help="Date and time of completion for this job."
)
job_state = fields.Selection(
selection=[
Expand Down
12 changes: 10 additions & 2 deletions base_report_to_printer/models/printing_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions base_report_to_printer/models/printing_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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()
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions base_report_to_printer/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions base_report_to_printer/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions base_report_to_printer/security/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@
<field name="name">Update printer wizard</field>
<field name="model_id" ref="model_printing_printer_update_wizard" />
<field name="group_id" ref="printing_group_manager" />
<field eval="1" name="perm_read" />
<field eval="1" name="perm_unlink" />
<field eval="1" name="perm_write" />
<field eval="1" name="perm_read" />
<field eval="1" name="perm_unlink" />
<field eval="1" name="perm_write" />
<field eval="1" name="perm_create" />
</record>
<record id="access_wizard_print_attachment_user" model="ir.model.access">
<field name="name">Print Attachment User</field>
Expand Down
57 changes: 34 additions & 23 deletions base_report_to_printer/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z 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.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* 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 }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -398,16 +399,17 @@ <h1 class="title">Report to printer</h1>
<li><a class="reference internal" href="#installation" id="toc-entry-1">Installation</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-2">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-3">Usage</a></li>
<li><a class="reference internal" href="#changelog" id="toc-entry-4">Changelog</a><ul>
<li><a class="reference internal" href="#section-1" id="toc-entry-5">13.0.1.0.0 (2019-09-30)</a></li>
<li><a class="reference internal" href="#section-2" id="toc-entry-6">12.0.1.0.0 (2018-02-04)</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-4">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#changelog" id="toc-entry-5">Changelog</a><ul>
<li><a class="reference internal" href="#section-1" id="toc-entry-6">13.0.1.0.0 (2019-09-30)</a></li>
<li><a class="reference internal" href="#section-2" id="toc-entry-7">12.0.1.0.0 (2018-02-04)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-7">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-8">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-9">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-10">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-11">Maintainers</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-8">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-9">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-10">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-11">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-12">Maintainers</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -438,9 +440,8 @@ <h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
information, you need to change the configuration of your CUPS server
and set the JobPrivateValue directive to “none” (or some other list of
values which does not include “job-name”) , and reload the server. See
cupsd.conf(5)
&lt;<a class="reference external" href="https://www.cups.org/doc/man-cupsd.conf.html&gt;">https://www.cups.org/doc/man-cupsd.conf.html\&gt;</a>
for details.</p>
cupsd.conf(5) &lt;<a class="reference external" href="https://www.cups.org/doc/man-cupsd.conf.html">https://www.cups.org/doc/man-cupsd.conf.html</a>&gt; for
details.</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
Expand All @@ -462,33 +463,41 @@ <h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
<p>When no tray is configured for a report and a user, the default tray
setup on the CUPS server is used.</p>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-4">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>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.</li>
</ul>
</div>
<div class="section" id="changelog">
<h1><a class="toc-backref" href="#toc-entry-4">Changelog</a></h1>
<h1><a class="toc-backref" href="#toc-entry-5">Changelog</a></h1>
<div class="section" id="section-1">
<h2><a class="toc-backref" href="#toc-entry-5">13.0.1.0.0 (2019-09-30)</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">13.0.1.0.0 (2019-09-30)</a></h2>
<ul class="simple">
<li>[RELEASE] Port from V12.</li>
</ul>
</div>
<div class="section" id="section-2">
<h2><a class="toc-backref" href="#toc-entry-6">12.0.1.0.0 (2018-02-04)</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">12.0.1.0.0 (2018-02-04)</a></h2>
<ul class="simple">
<li>[RELEASE] Port from V11.</li>
</ul>
</div>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-7">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-8">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/report-print-send/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/report-print-send/issues/new?body=module:%20base_report_to_printer%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-8">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-9">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-9">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-10">Authors</a></h2>
<ul class="simple">
<li>Agile Business Group &amp; Domsense</li>
<li>Pegueroles SCP</li>
Expand All @@ -499,7 +508,7 @@ <h2><a class="toc-backref" href="#toc-entry-9">Authors</a></h2>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-10">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-11">Contributors</a></h2>
<ul class="simple">
<li>Ferran Pegueroles &lt;<a class="reference external" href="mailto:ferran&#64;pegueroles.com">ferran&#64;pegueroles.com</a>&gt;</li>
<li>Albert Cervera i Areny &lt;<a class="reference external" href="mailto:albert&#64;nan-tic.com">albert&#64;nan-tic.com</a>&gt;</li>
Expand All @@ -521,9 +530,11 @@ <h2><a class="toc-backref" href="#toc-entry-10">Contributors</a></h2>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-12">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
Expand Down
Loading

0 comments on commit fc386a1

Please sign in to comment.