feat(iot): repackaged Odoo iot modules + Fusion Plating sensor wrapper
Phase A of the IoT initiative — gets the server-side infrastructure
in place before the Raspberry Pi hardware arrives, so the iot admin
UI + /fp/iot/ingest endpoint are ready to accept the first real
temperature reading as soon as the Pi is wired up.
New top-level folder: fusion_iot/
1. **iot_base/** — Odoo S.A. iot_base module, copied from
RePackaged-Odoo verbatim. LGPL-3 upstream, no changes needed.
2. **iot/** — Odoo S.A. iot module, repackaged:
- `models/update.py` neutralised (removed the publisher_warranty
IoT-Box-counting report that phones home to odoo.com for
enterprise licence enforcement)
- `iot_handlers/lib/load_worldline_library.sh` deleted (proprietary
Worldline payment lib fetch from download.odoo.com, not needed)
- `wizard/add_iot_box.py._connect_iot_box_with_pairing_code` —
upstream called odoo.com's iot-proxy to resolve pairing codes;
replaced with a no-op. Pi-side iot_drivers proxy registers
directly with this Odoo server instead.
- Manifest rebranded with an explicit changelog preamble.
3. **fusion_plating_iot/** — new plating-specific wrapper:
- `fp.tank.sensor` — maps an iot.device (or a direct-HTTP-ingest
sensor) to a fusion.plating.tank + fusion.plating.bath.parameter.
Supports DS18B20, PT100/1000, pH, conductivity, level. Per-sensor
alert_min/max overrides.
- `fp.tank.reading` — append-only time-series. On create, evaluates
against sensor's alert range. On in-spec → out-of-spec TRANSITION,
auto-raises a fusion.plating.quality.hold (once per excursion,
no spam during sustained out-of-spec).
- `POST /fp/iot/ingest` — shared-secret HTTP endpoint for sensors
bypassing the Pi proxy. Token via X-FP-IOT-Token header OR body.
Accepts single-reading or batch payloads.
- Menu under Plating → Operations → Sensors & Readings.
- Tank form inherits get a Sensors tab inline.
Deployed to entech. Verified end-to-end:
- Install: iot_base + iot + fusion_plating_iot all 'installed'
- Smoke test: in-spec → out-of-spec → hold raised (HOLD-0010);
continued excursion → NO duplicate hold; back-in-spec → NEW
excursion → NEW hold (HOLD-0011) ✓
- HTTP endpoint: correct token → 200 accepted; wrong token → 401;
unknown device_serial → 404; batch payload → 200 accepted=N ✓
Phase B (when Raspberry Pi hardware arrives): DS18B20 iot_handler
driver for the Pi-side iot_drivers proxy + systemd service on
vanilla Raspberry Pi OS + first live reading from physical probe.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
BIN
fusion_iot/iot/wizard/.___init__.py
Normal file
BIN
fusion_iot/iot/wizard/.___init__.py
Normal file
Binary file not shown.
BIN
fusion_iot/iot/wizard/._add_iot_box.py
Normal file
BIN
fusion_iot/iot/wizard/._add_iot_box.py
Normal file
Binary file not shown.
BIN
fusion_iot/iot/wizard/._add_iot_box_views.xml
Normal file
BIN
fusion_iot/iot/wizard/._add_iot_box_views.xml
Normal file
Binary file not shown.
BIN
fusion_iot/iot/wizard/._discovered_iot_box.py
Normal file
BIN
fusion_iot/iot/wizard/._discovered_iot_box.py
Normal file
Binary file not shown.
BIN
fusion_iot/iot/wizard/._select_printers.py
Normal file
BIN
fusion_iot/iot/wizard/._select_printers.py
Normal file
Binary file not shown.
BIN
fusion_iot/iot/wizard/._select_printers_views.xml
Normal file
BIN
fusion_iot/iot/wizard/._select_printers_views.xml
Normal file
Binary file not shown.
5
fusion_iot/iot/wizard/__init__.py
Normal file
5
fusion_iot/iot/wizard/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import add_iot_box
|
||||
from . import discovered_iot_box
|
||||
from . import select_printers
|
||||
178
fusion_iot/iot/wizard/add_iot_box.py
Normal file
178
fusion_iot/iot/wizard/add_iot_box.py
Normal file
@@ -0,0 +1,178 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import _, fields, models
|
||||
|
||||
import logging
|
||||
import requests
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AddIotBox(models.TransientModel):
|
||||
_name = 'add.iot.box'
|
||||
_description = 'Add IoT Box wizard'
|
||||
|
||||
# Depending on the stage different window actions are available
|
||||
stage = fields.Selection([
|
||||
('start', 'Start'),
|
||||
('connect', 'Connect'),
|
||||
('manual', 'Manual'),
|
||||
('pair_offline', 'Offline Pairing'),
|
||||
], string='Stage', default='start')
|
||||
|
||||
discovered_box_ids = fields.One2many("iot.discovered.box", "add_iot_box_wizard_id")
|
||||
iot_box_to_connect = fields.Many2one("iot.discovered.box")
|
||||
serial_number = fields.Char(string='Serial Number')
|
||||
pairing_code = fields.Char(string='Pairing Code')
|
||||
|
||||
offline_pairing_token = fields.Char(
|
||||
"Token", default=lambda self: self._compute_pairing_token(), readonly=True, store=False
|
||||
)
|
||||
|
||||
# ------------------------- IOT-PROXY CALLING METHODS -------------------------
|
||||
def _connect_iot_box_with_pairing_code(self):
|
||||
"""Community repackage — the upstream version called out to
|
||||
Odoo S.A.'s iot-proxy service at odoo.com to resolve pairing
|
||||
codes. That's phone-home for licensed IoT Boxes. In community
|
||||
mode we pair directly: the Pi-side iot_drivers proxy registers
|
||||
itself with this Odoo server using the shared token, so no
|
||||
third-party resolution is needed.
|
||||
|
||||
If a user gets to this wizard path anyway, log + show the
|
||||
"no box found" screen. The normal flow is for operators to
|
||||
use the direct pairing (or the /fp/iot/ingest endpoint for
|
||||
HTTP-only sensors).
|
||||
"""
|
||||
if self.iot_box_to_connect:
|
||||
self.pairing_code = self.iot_box_to_connect.pairing_code
|
||||
self.serial_number = self.iot_box_to_connect.serial_number
|
||||
_logger.info(
|
||||
'IoT pairing-code wizard invoked with code=%s, serial=%s — '
|
||||
'upstream odoo.com proxy call disabled in community repackage. '
|
||||
'Use direct IoT Box registration instead.',
|
||||
self.pairing_code, self.serial_number,
|
||||
)
|
||||
return self._open_no_iot_box_found_action()
|
||||
|
||||
# ------------------------- WIZARD OPEN ACTIONS -------------------------
|
||||
def _open_select_box_to_connect_action(self):
|
||||
self.stage = 'connect'
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'add.iot.box',
|
||||
'res_id': self.id,
|
||||
'name': _("Several IoT's detected"),
|
||||
'views': [[self.env.ref('iot.view_select_box_to_connect').id, 'form']],
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
def _open_enter_pairing_code_action(self):
|
||||
self.stage = 'connect'
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'add.iot.box',
|
||||
'res_id': self.id,
|
||||
'name': _("Searching for an IoT Box..."),
|
||||
'views': [[self.env.ref('iot.view_enter_pairing_code').id, 'form']],
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
def _open_no_iot_box_found_action(self):
|
||||
self.stage = 'manual'
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'add.iot.box',
|
||||
'res_id': self.id,
|
||||
'name': _("Searching for an IoT Box..."),
|
||||
'views': [[self.env.ref('iot.view_no_iot_box_found').id, 'form']],
|
||||
'target': 'new',
|
||||
'no_iot_found_found': True,
|
||||
}
|
||||
|
||||
def _open_connecting_action(self):
|
||||
if self.serial_number:
|
||||
name = _('IoT Box %s found. Connecting...', self.serial_number)
|
||||
else:
|
||||
name = _('IoT Box found. Connecting...')
|
||||
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'add.iot.box',
|
||||
'res_id': self.id,
|
||||
'name': name,
|
||||
'views': [[self.env.ref('iot.view_add_iot_box').id, 'form']],
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
def open_documentation_url(self):
|
||||
return {
|
||||
'type': 'ir.actions.act_url',
|
||||
'url': '#',
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
# ------------------------- WIZARD STAGE ACTIONS -------------------------
|
||||
|
||||
def _start_stage(self):
|
||||
"""
|
||||
Make a request to discover local IoT Boxes
|
||||
If none are found, open the pairing code wizard
|
||||
If only 1 is found, attempt to connect it directly
|
||||
If > 1 is found, open the select box wizard
|
||||
"""
|
||||
n_detected_iot_boxes = len(self.discovered_box_ids)
|
||||
|
||||
# If multiple IoT Boxes are found, ask the user to select one
|
||||
if n_detected_iot_boxes > 1:
|
||||
return self._open_select_box_to_connect_action()
|
||||
# If only one IoT Box is found, connect it directly without showing the wizard to the user
|
||||
elif n_detected_iot_boxes == 1:
|
||||
self.pairing_code = self.discovered_box_ids[0].pairing_code
|
||||
self.serial_number = self.discovered_box_ids[0].serial_number
|
||||
return self._connect_iot_box_with_pairing_code()
|
||||
# If no IoT Boxes are found, ask the user to enter the pairing code manually
|
||||
else:
|
||||
return self._open_no_iot_box_found_action()
|
||||
|
||||
def add_iot_box_wizard_action(self):
|
||||
"""
|
||||
Base action for the wizard used to connect IoT Boxes
|
||||
Depending on the stage of the wizard, different actions are available
|
||||
"""
|
||||
match self.stage:
|
||||
case 'start':
|
||||
return self._start_stage()
|
||||
case 'manual':
|
||||
return self._open_enter_pairing_code_action()
|
||||
case 'connect':
|
||||
return self._connect_iot_box_with_pairing_code()
|
||||
return None
|
||||
|
||||
def pair_offline(self):
|
||||
"""Use the token to pair an IoT Box.
|
||||
Allows to pair an IoT Box that is not connected to the internet
|
||||
"""
|
||||
if self.stage == 'pair_offline':
|
||||
self.stage = 'start'
|
||||
return self._start_stage()
|
||||
|
||||
self.stage = 'pair_offline'
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'add.iot.box',
|
||||
'res_id': self.id,
|
||||
'name': _("Pair an IoT Box offline"),
|
||||
'views': [[self.env.ref('iot.view_pair_offline').id, 'form']],
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
def _compute_pairing_token(self):
|
||||
icp_sudo = self.env['ir.config_parameter'].sudo()
|
||||
token = self.env['iot.box']._default_token()
|
||||
url = self.get_base_url()
|
||||
db_uuid = icp_sudo.get_param('database.uuid', default='')
|
||||
db_name = self.env.cr.dbname
|
||||
enterprise_code = icp_sudo.get_param('database.enterprise_code', default='')
|
||||
|
||||
return f"{url}?token={token}&db_uuid={db_uuid}&enterprise_code={enterprise_code}&db_name={db_name}"
|
||||
152
fusion_iot/iot/wizard/add_iot_box_views.xml
Normal file
152
fusion_iot/iot/wizard/add_iot_box_views.xml
Normal file
@@ -0,0 +1,152 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<!-- This view is used when waiting for an IoT Box to connect -->
|
||||
<record id="view_add_iot_box" model="ir.ui.view">
|
||||
<field name="name">Add IoT box</field>
|
||||
<field name="model">add.iot.box</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="IoT Box found. Connecting..." js_class="add_iot_box_wizard">
|
||||
<div>IoT Box detected correctly.</div>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
Setup in progress, should take maximum 1 minute...
|
||||
<span class="spinner-border spinner-border-sm"/>
|
||||
</div>
|
||||
<footer>
|
||||
<div class="d-flex justify-content-between w-100">
|
||||
<div class="d-flex gap-1">
|
||||
<button class="btn btn-secondary" string="Discard" data-hotkey="x" name="cancel" special="cancel"/>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- This view is used when the user is asked to enter the pairing code -->
|
||||
<record id="view_enter_pairing_code" model="ir.ui.view">
|
||||
<field name="name">Enter Pairing Code</field>
|
||||
<field name="model">add.iot.box</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="No IoT Box found">
|
||||
First, connect the IoT Box to internet, using an ethernet cable. Or, checkout the
|
||||
<a href="#" target="_blank" class="link fw-bold">documentation</a>
|
||||
for Wi-Fi.<br/>
|
||||
Then, connect the IoT Box to a printer (via USB cable) or a screen (via micro HDMI cable) to get the pairing code.<br/>
|
||||
<br/>
|
||||
<group class="col-md-8">
|
||||
<field name="pairing_code" placeholder="e.g. ABDE0123"/>
|
||||
</group>
|
||||
<footer>
|
||||
<div class="d-flex justify-content-between w-100">
|
||||
<div class="d-flex gap-1">
|
||||
<button id="pair_button" class="btn btn-primary" type="object" name="add_iot_box_wizard_action" string="Connect"/>
|
||||
<button class="btn btn-secondary" string="Discard" data-hotkey="x" name="cancel" special="cancel"/>
|
||||
</div>
|
||||
<button class="btn btn-secondary" string="Offline Pairing" name="pair_offline" groups="base.group_no_one" type="object"/>
|
||||
</div>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- This view is used when the user wants to connect an IoT Box with the token -->
|
||||
<record id="view_pair_offline" model="ir.ui.view">
|
||||
<field name="name">Pair an IoT Box offline</field>
|
||||
<field name="model">add.iot.box</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Pair an IoT Box offline">
|
||||
If your IoT Box has no access to the internet, you can pair it with your database using the pairing token.
|
||||
<ol>
|
||||
<li>Find the IP address of your IoT Box then connect to the web homepage.</li>
|
||||
<li>Then click on "Configure" under "Odoo database connected" section.</li>
|
||||
<li>Finally, paste the pairing token below in the "Server token" field.</li>
|
||||
</ol>
|
||||
<group>
|
||||
<field name="offline_pairing_token" widget="CopyClipboardChar" readonly="1"/>
|
||||
</group>
|
||||
<footer>
|
||||
<div class="d-flex justify-content-between w-100">
|
||||
<div class="d-flex gap-1">
|
||||
<button class="btn btn-primary" string="Standard Pairing" name="pair_offline" type="object"/>
|
||||
<button class="btn btn-secondary" string="Discard" data-hotkey="x" name="cancel" special="cancel"/>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- This view is used when multiple iot boxes have been found -->
|
||||
<record id="view_select_box_to_connect" model="ir.ui.view">
|
||||
<field name="name">Select Box To Connect</field>
|
||||
<field name="model">add.iot.box</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Select IoT Box to connect">
|
||||
Which one do you want to connect?<br/><br/>
|
||||
<group class="col-md-8">
|
||||
<!-- required is forced here because the record is created without a value -->
|
||||
<field name="iot_box_to_connect" widget="radio" required="1" domain="[['id', 'in', discovered_box_ids]]"/>
|
||||
</group>
|
||||
<footer>
|
||||
<div class="d-flex justify-content-between w-100">
|
||||
<div class="d-flex gap-1">
|
||||
<button id="pair_button" class="btn btn-primary" type="object" name="add_iot_box_wizard_action" string="Connect"/>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- This view is used when no iot boxes have been found -->
|
||||
<record id="view_no_iot_box_found" model="ir.ui.view">
|
||||
<field name="name">No IoT Box Found</field>
|
||||
<field name="model">add.iot.box</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="No IoT Box found" js_class="no_iot_box_found_wizard">
|
||||
<div class="d-flex flex-column flex-md-row gap-4 gap-md-3 text-center">
|
||||
<div class="d-flex flex-column flex-grow-1 align-items-center w-100">
|
||||
<img src="/iot/static/src/img/iot_power.svg" alt="Power is on" class="mb-3"/>
|
||||
<h5 class="h2">Power the box</h5>
|
||||
<p class="mb-0">Make sure the IoT Box is powered on.</p>
|
||||
</div>
|
||||
<div class="d-flex flex-column flex-grow-1 align-items-center w-100">
|
||||
<img src="/iot/static/src/img/network_light.svg" alt="Internet is connected" class="mb-3"/>
|
||||
<h5 class="h2">Check the lights</h5>
|
||||
<p class="mb-0">Make sure the Network lights are on.</p>
|
||||
</div>
|
||||
<div class="d-flex flex-column flex-grow-1 align-items-center w-100">
|
||||
<img src="/iot/static/src/img/pairing_code.svg" alt="Pairing code received from a printer or screen" class="mb-3"/>
|
||||
<h5 class="h2">Optional: Plug a screen</h5>
|
||||
<p class="mb-0">Plug a screen or a printer to get a status.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="discover_retry_spinner" class="d-flex gap-1 align-items-center mt-4">
|
||||
<span class="spinner-border spinner-border-sm"/>
|
||||
Searching for an IoT Box.
|
||||
<span id="discover_retry_countdown" class="fw-bold"/>
|
||||
</div>
|
||||
<p class="mb-0">Note: It takes ~1 minute. After that, try to pair manually.</p>
|
||||
<footer>
|
||||
<div class="d-flex justify-content-between w-100">
|
||||
<div class="d-flex gap-1">
|
||||
<button id="pair_code_button" class="btn btn-primary" type="object" name="add_iot_box_wizard_action" string="Use Pairing Code"/>
|
||||
<button class="btn btn-secondary" name="open_documentation_url" type="object" string="Documentation"/>
|
||||
<button class="btn btn-secondary" string="Discard" data-hotkey="x" name="cancel" special="cancel"/>
|
||||
</div>
|
||||
<button class="btn btn-secondary" string="Offline Pairing" name="pair_offline" type="object" groups="base.group_no_one"/>
|
||||
</div>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="action_add_iot_box" model="ir.actions.act_window">
|
||||
<field name="name">Connect my IoT Box</field>
|
||||
<field name="res_model">add.iot.box</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="view_add_iot_box"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</odoo>
|
||||
17
fusion_iot/iot/wizard/discovered_iot_box.py
Normal file
17
fusion_iot/iot/wizard/discovered_iot_box.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import _, fields, models
|
||||
|
||||
|
||||
class DiscoveredIotBox(models.TransientModel):
|
||||
_name = 'iot.discovered.box'
|
||||
_description = 'An IoT box that is in pairing mode'
|
||||
|
||||
name = fields.Char(compute="_compute_box_name")
|
||||
add_iot_box_wizard_id = fields.Many2one("add.iot.box")
|
||||
serial_number = fields.Char(readonly=True)
|
||||
pairing_code = fields.Char(readonly=True)
|
||||
|
||||
def _compute_box_name(self):
|
||||
for box in self:
|
||||
box.name = _("IoT Box %(serial_n)s %(pairing_code)s", serial_n=box.serial_number or "", pairing_code=box.pairing_code)
|
||||
13
fusion_iot/iot/wizard/select_printers.py
Normal file
13
fusion_iot/iot/wizard/select_printers.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class SelectPrintersWizard(models.TransientModel):
|
||||
_name = 'select.printers.wizard'
|
||||
_description = "Selection of printers"
|
||||
|
||||
device_ids = fields.Many2many('iot.device', domain=[('type', '=', 'printer')])
|
||||
display_device_ids = fields.Many2many('iot.device', relation='display_device_id_select_printer', domain=[('type', '=', 'printer')])
|
||||
do_not_ask_again = fields.Boolean("Do not ask me again", help="If checked, this dialog won't appear the next time you print and the selected printers will be used automatically.")
|
||||
22
fusion_iot/iot/wizard/select_printers_views.xml
Normal file
22
fusion_iot/iot/wizard/select_printers_views.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="view_select_printers_wizard" model="ir.ui.view">
|
||||
<field name="name">select.printers.wizard.form</field>
|
||||
<field name="model">select.printers.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form js_class="select_printers_wizard" string="Sales Details">
|
||||
<field name="display_device_ids" invisible="1"/>
|
||||
<group>
|
||||
<field name="device_ids" widget="many2many_tags" domain="[('id', 'in', display_device_ids)]" string="Printers"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="do_not_ask_again"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button string="Print" class="btn-primary" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user