Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions base_report_to_printer_websocket/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
===============================
Report to printer via WebSocket
===============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:de258c1feb02104fc70ac810fb99f19a11714bb4f55aad6173beddebecef3573
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freport--print--send-lightgray.png?logo=github
:target: https://github.com/OCA/report-print-send/tree/18.0/base_report_to_printer_websocket
:alt: OCA/report-print-send
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/report-print-send-18-0/report-print-send-18-0-base_report_to_printer_websocket
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/report-print-send&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends *base_report_to_printer* to send print jobs through
the Odoo Bus (WebSocket) instead of a traditional print server like
CUPS.

When a report is printed, the module encodes the rendered PDF in Base64
and sends a ``print_job`` message through the bus to the user configured
on the printer. A client-side listener running as that user receives the
payload and forwards it to the local printer.

Main features:

- No external print server required — works over the existing Odoo Bus.
- Sends print jobs as Base64-encoded PDFs via WebSocket.
- Each printer is bound to a specific Odoo user, so jobs are delivered
only to the right client-side agent.
- Compatible with the standard *base_report_to_printer* configuration
(global, per user, per report, per user + report).
- Works with
``odoo-print-client <https://pypi.org/project/odoo-print-client/>``\ \_
as the client-side agent to receive and print jobs.

**Table of contents**

.. contents::
:local:

Configuration
=============

1. Create a printer record in **Settings > Printing > Printers** with
the backend set to **WebSocket**.

2. Set the **System Name** to the name of the target printer as known by
the client-side listener (e.g. ``MFC-L3750CDW``). Leave it empty to
use the default system printer.

3. Set the **WebSocket User** to the Odoo user that will run the
``odoo-print-client`` agent. Print jobs are delivered through the bus
subscription of this user.

4. Assign the printer as the default globally, per user, or per report
following the standard *base_report_to_printer* workflow.

5. Install and run the ``odoo-print-client`` agent on the machine
connected to the printer

::

pip install odoo-print-client
odoo-printer --url "https://odoo.example.com" --db "prod" --user "admin" --password "admin"

See
``odoo-print-client on PyPI <https://pypi.org/project/odoo-print-client/>``\ \_
for full configuration options.

Usage
=====

Once configured, printing works transparently. When a user prints a
report that is set to *Send to Printer* and the assigned printer uses
the **WebSocket** backend, the module will:

1. Render the report as PDF.

2. Encode the PDF content in Base64.

3. Send a ``print_job`` message through the bus to the printer's
configured user with the following payload

::

{
"printer_name": "<system_name of the printer>",
"file_data": "<base64-encoded PDF>"
}

The recommended client-side agent is
``odoo-print-client <https://pypi.org/project/odoo-print-client/>``\ \_,
which connects as the configured user and forwards jobs to the local
printer.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/report-print-send/issues>`_.
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
`feedback <https://github.com/OCA/report-print-send/issues/new?body=module:%20base_report_to_printer_websocket%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ForgeFlow
* Dixmit

Contributors
------------

- `ForgeFlow <https://forgeflow.com>`__:

- David Jiménez david.jimenez@forgeflow.com

- `Dixmit <https://dixmit.com>`__:

- Enric Tobella

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

This module is part of the `OCA/report-print-send <https://github.com/OCA/report-print-send/tree/18.0/base_report_to_printer_websocket>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions base_report_to_printer_websocket/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
23 changes: 23 additions & 0 deletions base_report_to_printer_websocket/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2026 Dixmit
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Report to printer via WebSocket",
"version": "18.0.1.0.0",
"category": "Generic Modules/Base",
"author": "ForgeFlow,Dixmit,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/report-print-send",
"license": "AGPL-3",
"depends": ["base_report_to_printer", "bus"],
"data": [
"views/printing_printer.xml",
],
"assets": {
"web.assets_backend": [
"/base_report_to_printer_websocket/static/src/js/qweb_action_manager.esm.js",
],
},
"installable": True,
"application": False,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * base_report_to_printer_websocket
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 19.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: base_report_to_printer_websocket
#: model:ir.model.fields,field_description:base_report_to_printer_websocket.field_printing_printer__backend
msgid "Backend"
msgstr ""

#. module: base_report_to_printer_websocket
#. odoo-javascript
#: code:addons/base_report_to_printer_websocket/static/src/js/qweb_action_manager.esm.js:0
msgid "Could not send print job!"
msgstr ""

#. module: base_report_to_printer_websocket
#: model:ir.model.fields,field_description:base_report_to_printer_websocket.field_ir_websocket__display_name
#: model:ir.model.fields,field_description:base_report_to_printer_websocket.field_printing_printer__display_name
msgid "Display Name"
msgstr ""

#. module: base_report_to_printer_websocket
#: model:ir.model.fields,field_description:base_report_to_printer_websocket.field_ir_websocket__id
#: model:ir.model.fields,field_description:base_report_to_printer_websocket.field_printing_printer__id
msgid "ID"
msgstr ""

#. module: base_report_to_printer_websocket
#: model:ir.model,name:base_report_to_printer_websocket.model_printing_printer
msgid "Logical Printer"
msgstr ""

#. module: base_report_to_printer_websocket
#. odoo-javascript
#: code:addons/base_report_to_printer_websocket/static/src/js/qweb_action_manager.esm.js:0
msgid "Print job sent via WebSocket!"
msgstr ""

#. module: base_report_to_printer_websocket
#: model:ir.model.fields.selection,name:base_report_to_printer_websocket.selection__printing_printer__backend__websocket
msgid "WebSocket"
msgstr ""

#. module: base_report_to_printer_websocket
#: model:ir.model.fields,field_description:base_report_to_printer_websocket.field_printing_printer__websocket_user_id
msgid "Websocket User"
msgstr ""

#. module: base_report_to_printer_websocket
#: model:ir.model,name:base_report_to_printer_websocket.model_ir_websocket
msgid "websocket message handling"
msgstr ""
2 changes: 2 additions & 0 deletions base_report_to_printer_websocket/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import ir_websocket
from . import printing_printer
24 changes: 24 additions & 0 deletions base_report_to_printer_websocket/models/ir_websocket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2026 Dixmit
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class IrWebsocket(models.AbstractModel):
_inherit = "ir.websocket"

def _build_bus_channel_list(self, channels):
websocket_printers = (
self.env["printing.printer"]
.sudo()
.search(
[
("backend", "=", "websocket"),
("websocket_user_id", "=", self.env.uid),
]
)
)
for printer in websocket_printers:
channels.append(printer)
return super()._build_bus_channel_list(channels)
43 changes: 43 additions & 0 deletions base_report_to_printer_websocket/models/printing_printer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2026 Dixmit
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging
import os
from base64 import b64encode

from odoo import fields, models

_logger = logging.getLogger(__name__)


class PrintingPrinter(models.Model):
_inherit = "printing.printer"

backend = fields.Selection(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @DavidJForgeFlow

I was thinking to migrate 'base_report_to_printer_qztray' from v19 to v18 as you dou with this module.

My idea was to first create an [IMP] to 'base_report_to_printer' in order to add 'backend' field making the base module to be inheritable for other printing protocols in v18.

I can do it if you confirm that you're agree.

Thanks.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please do it. I will rebase when done! Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @DavidJForgeFlow , the IMP has been merged so you can rebase. Thanks.

selection_add=[("websocket", "WebSocket")],
ondelete={"websocket": "cascade"},
)
websocket_user_id = fields.Many2one(
"res.users",
)

def print_file(self, file_name, report=None, **print_opts):
if self.backend != "websocket":
return super().print_file(file_name, report=report, **print_opts)
self.ensure_one()
with open(file_name, "rb") as f:
content = f.read()
pdf_b64 = b64encode(content).decode("utf-8")
payload = {
"printer_name": self.system_name or "",
"file_data": pdf_b64,
"file_type": print_opts.get("doc_format", "qweb-pdf"),
}
self.env["bus.bus"]._sendone(self, "print_job", payload)
try:
os.remove(file_name)
except OSError as exc:
_logger.warning("Unable to remove temporary file %s: %s", file_name, exc)
_logger.debug("Print job sent via WebSocket to printer '%s'", self.name)
return True
3 changes: 3 additions & 0 deletions base_report_to_printer_websocket/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
18 changes: 18 additions & 0 deletions base_report_to_printer_websocket/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
1. Create a printer record in **Settings > Printing > Printers** with the
backend set to **WebSocket**.
2. Set the **System Name** to the name of the target printer as known by
the client-side listener (e.g. ``MFC-L3750CDW``). Leave it empty to
use the default system printer.
3. Set the **WebSocket User** to the Odoo user that will run the
``odoo-print-client`` agent. Print jobs are delivered through the bus
subscription of this user.
4. Assign the printer as the default globally, per user, or per report
following the standard *base_report_to_printer* workflow.
5. Install and run the ``odoo-print-client`` agent on the machine
connected to the printer

pip install odoo-print-client
odoo-printer --url "https://odoo.example.com" --db "prod" --user "admin" --password "admin"

See `odoo-print-client on PyPI <https://pypi.org/project/odoo-print-client/>`_
for full configuration options.
6 changes: 6 additions & 0 deletions base_report_to_printer_websocket/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- [ForgeFlow](https://forgeflow.com):
- David Jiménez <david.jimenez@forgeflow.com>

- [Dixmit](https://dixmit.com):
- Enric Tobella

18 changes: 18 additions & 0 deletions base_report_to_printer_websocket/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
This module extends *base_report_to_printer* to send print jobs through
the Odoo Bus (WebSocket) instead of a traditional print server like CUPS.

When a report is printed, the module encodes the rendered PDF in Base64
and sends a ``print_job`` message through the bus to the user configured
on the printer. A client-side listener running as that user receives
the payload and forwards it to the local printer.

Main features:

- No external print server required — works over the existing Odoo Bus.
- Sends print jobs as Base64-encoded PDFs via WebSocket.
- Each printer is bound to a specific Odoo user, so jobs are delivered
only to the right client-side agent.
- Compatible with the standard *base_report_to_printer* configuration
(global, per user, per report, per user + report).
- Works with `odoo-print-client <https://pypi.org/project/odoo-print-client/>`_
as the client-side agent to receive and print jobs.
17 changes: 17 additions & 0 deletions base_report_to_printer_websocket/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Once configured, printing works transparently. When a user prints a
report that is set to *Send to Printer* and the assigned printer uses the
**WebSocket** backend, the module will:

1. Render the report as PDF.
2. Encode the PDF content in Base64.
3. Send a ``print_job`` message through the bus to the printer's
configured user with the following payload

{
"printer_name": "<system_name of the printer>",
"file_data": "<base64-encoded PDF>"
}

The recommended client-side agent is
`odoo-print-client <https://pypi.org/project/odoo-print-client/>`_,
which connects as the configured user and forwards jobs to the local printer.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading