When an IoT box is configured as IoT box, it will send all the information about itself and its devices to its server. This way the server knows which ip and which devices are on the iotbox. Reports and in the enterprise version quality points will be linked to devices. In the module iot, the models and the controller are defined for this. There is also a javascript part with a widget for taking a measure and the possibility to link any report with a printer device.
58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
import base64
|
|
|
|
from odoo import api, fields, models, exceptions
|
|
|
|
# ----------------------------------------------------------
|
|
# Models for client
|
|
# ----------------------------------------------------------
|
|
class IotBox(models.Model):
|
|
_name = 'iot.box'
|
|
|
|
name = fields.Char('Name', readonly=True)
|
|
identifier = fields.Char(string='Identifier (Mac Address)', readonly=True)
|
|
device_ids = fields.One2many('iot.device', 'iot_id', string="Devices", readonly=True)
|
|
ip = fields.Char('IP Address', readonly=True)
|
|
screen_url = fields.Char('Screen URL', help="Url of the page that will be displayed by hdmi port of the box.")
|
|
|
|
|
|
class IotDevice(models.Model):
|
|
_name = 'iot.device'
|
|
|
|
iot_id = fields.Many2one('iot.box', string='IoT Box', required = True)
|
|
name = fields.Char('Name')
|
|
identifier = fields.Char(string='Identifier', readonly=True)
|
|
type = fields.Selection([
|
|
('printer', 'Printer'),
|
|
('camera', 'Camera'),
|
|
('device', 'Device'),
|
|
], readonly=True, default='device', string='Type',
|
|
help="Type of device.")
|
|
connection = fields.Selection([
|
|
('network', 'Network'),
|
|
('direct', 'USB'),
|
|
('bluetooth', 'Bluetooth')
|
|
], readonly=True, string="Connection",
|
|
help="Type of connection.")
|
|
report_ids = fields.One2many('ir.actions.report', 'device_id', string='Reports')
|
|
|
|
def name_get(self):
|
|
return [(i.id, "[" + i.iot_id.name +"] " + i.name) for i in self]
|
|
|
|
|
|
class IrActionReport(models.Model):
|
|
_inherit = 'ir.actions.report'
|
|
|
|
device_id = fields.Many2one('iot.device', string='IoT Device', domain="[('device_type', '=', 'printer')]",
|
|
help='When setting a device here, the report will be printed through this device on the iotbox')
|
|
|
|
def iot_render(self, res_ids, data=None):
|
|
if self.mapped('device_id'):
|
|
device = self.mapped('device_id')[0]
|
|
else:
|
|
device = self.env['iot.device'].browse(data['device_id'])
|
|
composite_url = "http://" + device.iot_id.ip + ":8069/driveraction/" + device.identifier
|
|
datas = self.render(res_ids, data=data)
|
|
type = datas[1]
|
|
data_bytes = datas[0]
|
|
data_base64 = base64.b64encode(data_bytes)
|
|
return composite_url, type, data_base64 |