mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-19 15:12:08 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
50
odoo-bringout-oca-iot-iot_oca/iot_oca/models/iot_device.py
Normal file
50
odoo-bringout-oca-iot-iot_oca/iot_oca/models/iot_device.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# Copyright (C) 2018 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class IoTDevice(models.Model):
|
||||
_name = "iot.device"
|
||||
_description = "IoT Device"
|
||||
_inherit = "image.mixin"
|
||||
|
||||
name = fields.Char(required=True)
|
||||
communication_system_id = fields.Many2one("iot.communication.system", required=True)
|
||||
action_ids = fields.One2many("iot.device.action", inverse_name="device_id")
|
||||
active = fields.Boolean(default=True)
|
||||
state = fields.Selection([], readonly=True)
|
||||
model = fields.Char()
|
||||
ip = fields.Char(string="IP")
|
||||
action_count = fields.Integer(compute="_compute_action_count")
|
||||
group_id = fields.Many2one("iot.device.group")
|
||||
tag_ids = fields.Many2many("iot.device.tag")
|
||||
color = fields.Integer()
|
||||
last_contact_date = fields.Datetime(readonly=True)
|
||||
icon = fields.Selection(
|
||||
[
|
||||
("fa fa-television fa-4x", "television"),
|
||||
("fa fa-wifi fa-4x", "wifi"),
|
||||
("fa fa-laptop fa-4x", "laptop"),
|
||||
("fa fa-desktop fa-4x", "desktop"),
|
||||
("fa fa-archive fa-4x", "archive"),
|
||||
("fa fa-mobile fa-6x", "mobile"),
|
||||
]
|
||||
)
|
||||
|
||||
@api.depends("action_ids")
|
||||
def _compute_action_count(self):
|
||||
for record in self:
|
||||
record.action_count = len(record.action_ids)
|
||||
|
||||
def device_run_action(self):
|
||||
system_action = self.env["iot.communication.system.action"].browse(
|
||||
self.env.context.get("iot_communication_system_action_id")
|
||||
)
|
||||
for rec in self:
|
||||
action = self.env["iot.device.action"].create(
|
||||
{
|
||||
"device_id": rec.id,
|
||||
"communication_system_action_id": system_action.id,
|
||||
}
|
||||
)
|
||||
action.run()
|
||||
Loading…
Add table
Add a link
Reference in a new issue