Skip to content

Commit cd8e9cc

Browse files
[IMP] Refactor to extract CUPS support into new module
1 parent 91e7cc0 commit cd8e9cc

100 files changed

Lines changed: 26220 additions & 1321 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright (C) 2022 Raumschmiede GmbH - Christopher Hansen (<https://www.raumschmiede.de>)
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
import logging
54

65
from odoo.addons.base.tests.common import BaseCommon
76

@@ -15,13 +14,11 @@ def setUpClass(cls):
1514
cls.Model = cls.env["ir.actions.report"].with_context(
1615
skip_printer_exception=True
1716
)
18-
cls.server = cls.env["printing.server"].create({})
1917

2018
def new_printer(self):
2119
return self.env["printing.printer"].create(
2220
{
2321
"name": "Printer",
24-
"server_id": self.server.id,
2522
"system_name": "Sys Name",
2623
"default": True,
2724
"status": "unknown",
@@ -38,16 +35,11 @@ def test_print_behavior_user_label_printer(self):
3835
report.label = True
3936
self.env.user.printing_action = "client"
4037
self.env.user.default_label_printer_id = self.new_printer()
41-
with (
42-
self.assertLogs(level=logging.WARNING) as logs,
43-
):
44-
self.assertEqual(
45-
report.behaviour(),
46-
{
47-
"action": "client",
48-
"printer": self.env.user.default_label_printer_id,
49-
"tray": False,
50-
},
51-
)
52-
self.assertEqual(len(logs.records), 1)
53-
self.assertEqual(logs.records[0].levelno, logging.WARNING)
38+
self.assertEqual(
39+
report.behaviour(),
40+
{
41+
"action": "client",
42+
"printer": self.env.user.default_label_printer_id,
43+
"tray": False,
44+
},
45+
)

base_report_to_printer/README.rst

Lines changed: 133 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Report to printer
1111
!! This file is generated by oca-gen-addon-readme !!
1212
!! changes will be overwritten. !!
1313
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14-
!! source digest: sha256:411351c67395d3219ea49f07addba2966080696f3b776d899712288e24f98fc2
14+
!! source digest: sha256:e5af916528d668b5628606b5b2216ec40d3f05f183d01eb157311e01719dcb49
1515
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1616
1717
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -32,33 +32,32 @@ Report to printer
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
3434

35-
This module allows users to send reports to a printer attached to the
36-
server.
35+
This module provides the core framework to send Odoo reports directly to
36+
printers. It defines the base models, configuration options and printing
37+
workflow, without depending on a specific printing protocol.
3738

38-
It adds an optional behaviour on reports to send it directly to a
39-
printer.
39+
The actual connection with printers is delegated to extension modules
40+
(e.g. base_report_to_printer_cups), which implement support for a given
41+
printing backend.
4042

41-
- Send to Client is the default behaviour providing you a downloadable
42-
PDF
43-
- Send to Printer prints the report on selected printer
43+
Key features:
4444

45-
It detects trays on printers installation plus permits to select the
46-
paper source on which you want to print directly.
45+
Flexible report output behavior:
4746

48-
Report behaviour is defined by settings.
47+
Send to Client (default): generates a downloadable PDF.
4948

50-
You will find this option on default user config, on default report
51-
config and on specific config per user per report.
49+
Send to Printer: sends the report directly to a configured printer (via
50+
backend module).
5251

53-
This allows you to dedicate a specific paper source for example for
54-
preprinted paper such as payment slip.
52+
Support for user-level, report-level, and combined user/report printing
53+
rules.
5554

56-
Settings can be configured:
55+
Extensible design: new modules can add support for additional printing
56+
systems or protocols.
5757

58-
- globally
59-
- per user
60-
- per report
61-
- per user and report
58+
This modular approach allows administrators to configure printing
59+
globally, per user, per report, or per user/report combination, while
60+
keeping the printing backend independent and replaceable.
6261

6362
**Table of contents**
6463

@@ -68,64 +67,138 @@ Settings can be configured:
6867
Installation
6968
============
7069

71-
To install this module, you need to:
7270

73-
1. Install PyCups - https://pypi.python.org/pypi/pycups
74-
75-
.. code:: bash
76-
77-
sudo apt-get install cups
78-
sudo apt-get install libcups2-dev
79-
sudo apt-get install python3-dev
80-
sudo pip install pycups
8171

8272
Configuration
8373
=============
8474

85-
To configure this module, you need to:
75+
Configuration Guide
76+
77+
To configure and start using the Base Report to Printer module, follow
78+
these steps:
79+
80+
1. User Access Rights
81+
82+
Go to Settings → Users & Companies → Users.
83+
84+
Open the user form and in the Access Rights tab, enable:
85+
86+
Printing / Print User → grants access to the printing menu and
87+
user-specific printing preferences.
88+
89+
2. Global Printing Settings
90+
91+
Navigate to Settings → Technical → Printing → Printing Settings.
92+
93+
Define the default printing behavior for reports:
94+
95+
Send to Client (default): generates a downloadable PDF.
96+
97+
Send to Printer: sends the report directly to a configured printer
98+
(requires a backend module such as base_report_to_printer_cups).
99+
100+
3. User Preferences
101+
102+
Each user can configure their own printing behavior:
103+
104+
Go to Preferences (top-right menu, click on your name).
105+
106+
In the Printing section, choose:
107+
108+
Default action (Send to Client / Send to Printer).
109+
110+
Preferred printer (if a backend module is installed and printers are
111+
detected).
112+
113+
4. Report-Specific Configuration
114+
115+
Go to Settings → Technical → Reports → Reports.
116+
117+
For each report, you can define:
86118

87-
1. Enable the "Printing / Print User" option under access rights to give
88-
users the ability to view the print menu.
119+
Default printing action.
89120

90-
The jobs will be sent to the printer with a name matching the
91-
print_report_name of the report (truncated at 80 characters). By default
92-
this will not be displayed by CUPS web interface or in Odoo. To see this
93-
information, you need to change the configuration of your CUPS server
94-
and set the JobPrivateValue directive to "none" (or some other list of
95-
values which does not include "job-name") , and reload the server. See
96-
cupsd.conf(5)
97-
<`https://www.cups.org/doc/man-cupsd.conf.html\\> <https://www.cups.org/doc/man-cupsd.conf.html\>>`__
98-
for details.
121+
Default printer (if available).
122+
123+
These settings can be overridden at the user level.
124+
125+
5. Per User & Report Combination
126+
127+
Navigate to Settings → Technical → Printing → Report Configurations.
128+
129+
Here you can assign specific rules combining:
130+
131+
A user.
132+
133+
A report.
134+
135+
A printing action (Send to Client / Send to Printer).
136+
137+
A printer and tray (if supported by the backend).
138+
139+
6. Installing a Backend (e.g., CUPS)
140+
141+
The base module does not include any printing backend. To connect with
142+
actual printers you must install an extension module, such as:
143+
144+
base_report_to_printer_cups → adds support for CUPS printers, trays, and
145+
job management.
146+
147+
Once installed, printers from the backend will be available in the
148+
configuration menus above.
99149

100150
Usage
101151
=====
102152

103-
Guidelines for use:
153+
Usage
154+
=====
104155

105-
- To update the CUPS printers in *Settings > Printing > Update
106-
Printers from CUPS*
107-
- To print a report on a specific printer or tray, you can change
108-
these in *Settings > Printing > Reports* to define default
109-
behaviour.
110-
- To print a report on a specific printer and/or tray for a user, you
111-
can change these in *Settings > Printing > Reports* in *Specific
112-
actions per user*
113-
- Users may also select a default action, printer or tray in their
114-
preferences.
156+
Guidelines for use:
115157

116-
When no tray is configured for a report and a user, the default tray
117-
setup on the CUPS server is used.
158+
- To use a specific printing backend (e.g. CUPS), make sure the
159+
corresponding module (such as ``base_report_to_printer_cups``) is
160+
installed and configured.
161+
- To print a report on a specific printer or tray, you can configure
162+
defaults in *Settings > Printing > Reports*.
163+
- To define user-specific behaviour, go to *Settings > Printing >
164+
Reports* and configure *Specific actions per user*.
165+
- Each user can also select a default action, printer or tray in their
166+
*Preferences*.
167+
- When no tray is configured for a report or a user, the default tray
168+
defined by the printing backend (e.g. the CUPS server) will be used.
169+
170+
Notes
171+
-----
172+
173+
- This module (``base_report_to_printer``) only provides the **base
174+
framework**.
175+
- To connect with a real print system, you must install an additional
176+
backend module (e.g. ``base_report_to_printer_cups`` for CUPS).
177+
- Other backend modules can be developed to support different print
178+
protocols or environments.
118179

119180
Known issues / Roadmap
120181
======================
121182

122-
- With threaded printing there's no download fallback when the issue
123-
isn't detected by the CUPS Odoo backend. To able to do it, we would
124-
need to notify the bus or use web_notify for it.
183+
125184

126185
Changelog
127186
=========
128187

188+
18.0.1.0.0 (2025-10-15)
189+
-----------------------
190+
191+
- [REFAC] Extracted all CUPS-specific functionality into a dedicated
192+
module: ``base_report_to_printer_cups``.
193+
- [ADD] Introduced a base abstraction layer for report-to-printer, to
194+
allow adding new backends (protocols) without modifying the core
195+
module.
196+
- [IMP] Improved configuration instructions (global, per-user,
197+
per-report, and per user+report).
198+
- [CLEAN] Updated documentation and module description to reflect new
199+
architecture.
200+
-
201+
129202
13.0.1.0.0 (2019-09-30)
130203
-----------------------
131204

@@ -180,12 +253,13 @@ Contributors
180253
- Akim Juillerat <[email protected]>
181254
- Jacques-Etienne Baudoux (BCIM) <[email protected]>
182255
- Tris Doan <[email protected]>
256+
- Miquel Alzanillas <[email protected]>
183257

184258
Other credits
185259
-------------
186260

187-
The migration of this module from 17.0 to 18.0 was financially supported
188-
by Camptocamp.
261+
The migration of the original module (base_report_to_printer) from 17.0
262+
to 18.0 was financially supported by Camptocamp.
189263

190264
Maintainers
191265
-----------

base_report_to_printer/__manifest__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@
1818
"data": [
1919
"data/printing_data.xml",
2020
"security/security.xml",
21-
"security/ir.model.access.csv",
2221
"views/printing_printer.xml",
23-
"views/printing_server.xml",
2422
"views/printing_job.xml",
2523
"views/printing_report.xml",
26-
"views/res_users.xml",
2724
"views/ir_actions_report.xml",
25+
"views/res_users.xml",
2826
"wizards/print_attachment_report.xml",
29-
"wizards/printing_printer_update_wizard_view.xml",
3027
],
3128
"assets": {
3229
"web.assets_backend": [
@@ -35,5 +32,4 @@
3532
},
3633
"installable": True,
3734
"application": False,
38-
"external_dependencies": {"python": ["pycups"]},
3935
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
update printing_server set active=false;
21
update printing_printer set active=false;

base_report_to_printer/data/printing_data.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@
99
<field name="name">Send to Client</field>
1010
<field name="action_type">client</field>
1111
</record>
12-
<record forcecreate="True" id="ir_cron_update_printers" model="ir.cron">
13-
<field name="name">Update Printers Jobs</field>
14-
<field name="active" eval="True" />
15-
<field name="user_id" ref="base.user_root" />
16-
<field name="interval_number">1</field>
17-
<field name="interval_type">minutes</field>
18-
<field name="model_id" ref="base_report_to_printer.model_printing_server" />
19-
<field name="state">code</field>
20-
<field name="code">model.action_update_jobs()</field>
21-
</record>
2212
<function
2313
model="ir.default"
2414
name="set"

base_report_to_printer/models/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from . import printing_action
33
from . import printing_job
44
from . import printing_printer
5-
from . import printing_server
65
from . import printing_report_xml_action
76
from . import printing_tray
87
from . import res_users

base_report_to_printer/models/ir_actions_report.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
66
# Copyright 2024 Tecnativa - Sergio Teruel
77
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
8+
import logging
89
import threading
910
from time import time
1011

1112
from odoo import _, api, exceptions, fields, models, registry
1213
from odoo.tools.safe_eval import safe_eval
1314

15+
_logger = logging.getLogger(__name__)
16+
1417
REPORT_TYPES = {"qweb-pdf": "pdf", "qweb-text": "text"}
1518

1619

@@ -153,6 +156,9 @@ def print_document(self, record_ids, data=None):
153156
"""Print a document, do not return the document file"""
154157
report_type = REPORT_TYPES.get(self.report_type)
155158
if not report_type:
159+
_logger.warning(
160+
"Report type %s not supported for direct printing", self.report_type
161+
)
156162
raise exceptions.UserError(
157163
_("This report type (%s) is not supported by direct printing!")
158164
% str(self.report_type)

0 commit comments

Comments
 (0)