Commit Graph
6 Commits
Author SHA1 Message Date
Loan (LSE) ce59fd6edb [FIX] hw_drivers: reconnect on server disconnection
To reproduce:
 1. Sync the IoT with a 17 database
 2. Once it is set up, force shut down the server by Ctrl+C 2 times
 3. Wait a few seconds:
=> crash of `WebsocketClient` thread with the following traceback:
```
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_i>
self.run()
  File "/home/pi/odoo/addons/hw_drivers/websocket_client.py", line 83>
self.ws.run_forever()
  File "/usr/local/lib/python3.11/dist-packages/websocket/_app.py", l>
raise WebSocketException("socket is already opened")
websocket._exceptions
WebSocketException
socket is already opened
```

The IoT synchronised servers can stop in 2 ways that we need to handle:
 A. Gracefully (Ctrl+C):
  In this case a disconnection signal is sent to the IoT-box
  The websocket is properly closed, but it needs to be established a new connection when
  the server will be back.
  Solution: `while True` loop as `run_forever` will return on close.
            `time.sleep` for the reconnection delay

 B. Forced/killed (Ctrl+C 2 times):
  In this case there is no disconnection signal received
  Solution: use `reconnect` that will automatically take care re-attempting a connection

  This will also happen with the graceful quit as `reconnect` will trigger if the server
  is offline while attempting the new connection

In both case, we perform a reconnection attempt with a delay of 10 seconds to avoid
spamming the database

After this commit:
 The websocket will reconnect itself automatically after 10 seconds
 if the connection is disrupted

opw-3612528

closes odoo/odoo#147858

Signed-off-by: Yaroslav Soroko (yaso) <yaso@odoo.com>
2024-01-03 16:59:17 +00:00
vifo 1be5133e74 [FIX] iot: Parse websocket url with ulrllib
Before, the websocket client was built manually, usign string
concatenation.
Now, urllib.parse() is used to appropriately adapt the database URL.
This update enhances security.

closes odoo/odoo#144303

Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
2023-12-11 09:56:49 +00:00
vifo d769aba6c5 [FIX] iot: change imports order websocket_client
The order of the imports have been changed in websocket_client.py to
follow odoo guidelines

closes odoo/odoo#144188

Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
2023-11-30 18:37:57 +00:00
vifo 65a5a12c7b [FIX] iot: Remove the useless function start_client
Previously, there was a function called 'start_client' that was invoked
by the 'run' function. As 'start_client' was solely invoked within 'run'
and served no additional purpose, its functionality has been incorporated
directly into the 'run' function.

closes odoo/odoo#144134

Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
2023-11-30 18:37:54 +00:00
vifo 391eac2447 [FIX] iot: Build the url of iot_channel with dumps
Before, the url was built with string comprehension.
Now json.dumps is use to ensure that the JSON sent is
valid

closes odoo/odoo#144125

Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
2023-11-30 14:48:13 +00:00
vifo adaf5b2873 [IMP] iot: Enable multiple printing per report via WebSocket
-Implemented a WebSocket service to facilitate communication with the IoT box. This enables printing reports on a network different from the browser. Before it was a long polling connection
-Implemented the ability to link multiple printers to a single report. Before it was possible to link only one printer er report
-When multiple printers are linked, a pop-up will prompt the user to select the preferred printers.
-The user's printer selection will be stored in the browser's local storage.
-Additionally, a reset button has been added to clear the printer selection.

task-3193258

closes odoo/odoo#129164

Related: odoo/enterprise#44398
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
2023-10-26 13:41:03 +00:00