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>
106 lines
4.0 KiB
JavaScript
106 lines
4.0 KiB
JavaScript
import { _t } from "@web/core/l10n/translation";
|
|
import { registry } from "@web/core/registry";
|
|
import { browser } from "@web/core/browser/browser"
|
|
import {
|
|
IOT_REPORT_PREFERENCE_LOCAL_STORAGE_KEY,
|
|
setReportIdInBrowserLocalStorage,
|
|
} from "./client_action/delete_local_storage";
|
|
import { uuid } from "@web/core/utils/strings";
|
|
|
|
/**
|
|
* Method to print the report with the selected devices
|
|
*
|
|
* @param env Environment
|
|
* @param args Arguments to render the report (report_id, active_record_ids, report_data)
|
|
* @param selected_device_ids Selected device ids (those stored in local storage)
|
|
* @returns {Promise<void>}
|
|
*/
|
|
export async function printReport(env, args, selected_device_ids) {
|
|
const orm = env.services.orm;
|
|
const notification = env.services.notification;
|
|
const iotHttp = env.services.iot_http;
|
|
|
|
const [report_id, active_record_ids, report_data] = args;
|
|
const jobs = await orm.call(
|
|
"ir.actions.report", "render_document",
|
|
[report_id, selected_device_ids, active_record_ids, report_data]
|
|
);
|
|
|
|
for (const job of jobs) {
|
|
const { iotBoxId, deviceIdentifier, deviceName, document } = job;
|
|
const removeSendingNotification = notification.add(_t("Sending document to printer %s...", deviceName), {
|
|
type: "info",
|
|
sticky: true,
|
|
});
|
|
|
|
await iotHttp.action(iotBoxId, deviceIdentifier, { document, print_id: uuid() }, () => {
|
|
removeSendingNotification?.();
|
|
notification.add(_t("Started printing operation on printer %s...", deviceName), { type: "success" });
|
|
});
|
|
}
|
|
}
|
|
|
|
export async function getSelectedPrintersForReport(reportId, env) {
|
|
const { orm, action, ui } = env.services;
|
|
const deviceSettingsByReportId = JSON.parse(browser.localStorage.getItem(IOT_REPORT_PREFERENCE_LOCAL_STORAGE_KEY));
|
|
const deviceSettings = deviceSettingsByReportId?.[reportId];
|
|
|
|
if (deviceSettings && deviceSettings.skipDialog) {
|
|
return deviceSettings.selectedDevices;
|
|
}
|
|
|
|
// Open IoT devices selection wizard
|
|
const openDeviceSelectionWizard = await orm.call("ir.actions.report", "get_action_wizard", [reportId, deviceSettings?.selectedDevices]);
|
|
await action.doAction(openDeviceSelectionWizard);
|
|
|
|
// If the UI is currently blocked, we need to temporarily unblock it or the user won't be able to select the printer
|
|
const uiWasBlocked = ui.isBlocked;
|
|
if (uiWasBlocked) {
|
|
ui.unblock();
|
|
}
|
|
|
|
// Wait for the popup to be closed and a printer selected
|
|
return new Promise((resolve) => {
|
|
const onPrinterSelected = (event) => {
|
|
if (event.detail.reportId === reportId) {
|
|
const newDeviceSettings = event.detail.deviceSettings;
|
|
if (newDeviceSettings) {
|
|
setReportIdInBrowserLocalStorage(reportId, newDeviceSettings);
|
|
}
|
|
resolve(newDeviceSettings ? newDeviceSettings.selectedDevices : null);
|
|
env.bus.removeEventListener("printer-selected", onPrinterSelected);
|
|
if (uiWasBlocked) {
|
|
ui.block();
|
|
}
|
|
}
|
|
};
|
|
env.bus.addEventListener("printer-selected", onPrinterSelected);
|
|
});
|
|
}
|
|
|
|
async function iotReportActionHandler(action, options, env) {
|
|
if (action.device_ids && action.device_ids.length) {
|
|
action.data ??= {};
|
|
const args = [action.id, action.context.active_ids, action.data];
|
|
const reportId = action.id;
|
|
const printerIds = await getSelectedPrintersForReport(reportId, env);
|
|
|
|
if (!printerIds) {
|
|
// If the user does not select any printer, fall back to normal printing
|
|
return false;
|
|
}
|
|
|
|
env.services.ui.block();
|
|
// Try longpolling then websocket
|
|
await printReport(env, args, printerIds);
|
|
env.services.ui.unblock();
|
|
|
|
options.onClose?.();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
registry
|
|
.category("ir.actions.report handlers")
|
|
.add("iot_report_action_handler", iotReportActionHandler);
|