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
9 changes: 7 additions & 2 deletions base_report_to_printer_websocket/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ Authors
Contributors
------------

- David Jiménez david.jimenez@forgeflow.com
- Enric Tobella enric.tobella@dixmit.com
- `ForgeFlow <https://forgeflow.com>`__:

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

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

- Enric Tobella

Maintainers
-----------
Expand Down
17 changes: 9 additions & 8 deletions base_report_to_printer_websocket/models/ir_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ class IrWebsocket(models.AbstractModel):
_inherit = "ir.websocket"

def _build_bus_channel_list(self, channels):
ws_channels = set(
websocket_printers = (
self.env["printing.printer"]
.sudo()
.search([("backend", "=", "websocket"), ("websocket_channel", "!=", False)])
.mapped("websocket_channel")
.search(
[
("backend", "=", "websocket"),
("websocket_user_id", "=", self.env.uid),
]
)
)
is_printing_user = self.env.uid and self.env.user.has_group(
"base_report_to_printer.printing_group_user"
)
if not is_printing_user:
channels = [ch for ch in channels if ch not in ws_channels]
for printer in websocket_printers:
channels.append(printer)
return super()._build_bus_channel_list(channels)
9 changes: 3 additions & 6 deletions base_report_to_printer_websocket/models/printing_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class PrintingPrinter(models.Model):
selection_add=[("websocket", "WebSocket")],
ondelete={"websocket": "cascade"},
)
websocket_channel = fields.Char(
string="WebSocket Channel",
default="printer",
help="Channel name used to route print jobs to the correct WebSocket client.",
websocket_user_id = fields.Many2one(
"res.users",
)

def print_document(
Expand All @@ -39,7 +37,6 @@ def print_document(
"file_data": pdf_b64,
"file_type": doc_format,
}
channel = self.websocket_channel or "printer"
self.env["bus.bus"]._sendone(channel, "print_job", payload)
self.env["bus.bus"]._sendone(self, "print_job", payload)
_logger.info("Print job sent via WebSocket to printer '%s'", self.name)
return True
8 changes: 6 additions & 2 deletions base_report_to_printer_websocket/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
- David Jiménez <david.jimenez@forgeflow.com>
- Enric Tobella <enric.tobella@dixmit.com>
- [ForgeFlow](https://forgeflow.com):
- David Jiménez <david.jimenez@forgeflow.com>

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

Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,14 @@ <h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<ul class="simple">
<li><a class="reference external" href="https://forgeflow.com">ForgeFlow</a>:<ul>
<li>David Jiménez <a class="reference external" href="mailto:david.jimenez&#64;forgeflow.com">david.jimenez&#64;forgeflow.com</a></li>
<li>Enric Tobella <a class="reference external" href="mailto:enric.tobella&#64;dixmit.com">enric.tobella&#64;dixmit.com</a></li>
</ul>
</li>
<li><a class="reference external" href="https://dixmit.com">Dixmit</a>:<ul>
<li>Enric Tobella</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
6 changes: 5 additions & 1 deletion base_report_to_printer_websocket/views/printing_printer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
<field name="model">printing.printer</field>
<field name="arch" type="xml">
<group name="name" position="inside">
<field name="websocket_channel" invisible="backend != 'websocket'" />
<field
name="websocket_user_id"
invisible="backend != 'websocket'"
required="backend == 'websocket'"
/>
</group>
</field>
</record>
Expand Down
Loading