-
-
Notifications
You must be signed in to change notification settings - Fork 358
[18.0][MIG] base_report_to_printer_websocket #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DavidJForgeFlow
wants to merge
4
commits into
OCA:18.0
Choose a base branch
from
ForgeFlow:18.0-mig-base_report_to_printer_websocket
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| } |
63 changes: 63 additions & 0 deletions
63
base_report_to_printer_websocket/i18n/base_report_to_printer_websocket.pot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from . import ir_websocket | ||
| from . import printing_printer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
43
base_report_to_printer_websocket/models/printing_printer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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( | ||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [build-system] | ||
| requires = ["whool"] | ||
| build-backend = "whool.buildapi" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.