mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-19 19:12:00 +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
6
odoo-bringout-oca-iot-iot_oca/iot_oca/models/__init__.py
Normal file
6
odoo-bringout-oca-iot-iot_oca/iot_oca/models/__init__.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from . import iot_device
|
||||
from . import iot_device_action
|
||||
from . import iot_communication_system
|
||||
from . import iot_communication_system_action
|
||||
from . import iot_device_group
|
||||
from . import iot_device_tag
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# Copyright (C) 2018 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class IoTCommunicationSystem(models.Model):
|
||||
_name = "iot.communication.system"
|
||||
_description = "IoT Communication System"
|
||||
# TODO: Rename it to iot.communication.system System is confusing
|
||||
|
||||
name = fields.Char(required=True)
|
||||
device_ids = fields.One2many("iot.device", inverse_name="communication_system_id")
|
||||
communication_system_action_ids = fields.One2many(
|
||||
"iot.communication.system.action", inverse_name="communication_system_id"
|
||||
)
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
# Copyright (C) 2018 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
import logging
|
||||
import traceback
|
||||
from io import StringIO
|
||||
|
||||
from odoo import _, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IoTSystemAction(models.Model):
|
||||
_name = "iot.communication.system.action"
|
||||
_description = "IoT Communication System action"
|
||||
|
||||
name = fields.Char(required=True)
|
||||
communication_system_id = fields.Many2one("iot.communication.system", required=True)
|
||||
|
||||
def _run(self, device_action):
|
||||
raise ValidationError(_("Action cannot be processed"))
|
||||
|
||||
def run(self, device_action):
|
||||
try:
|
||||
result = self._run(device_action)
|
||||
return "ok", result
|
||||
except Exception:
|
||||
buff = StringIO()
|
||||
traceback.print_exc(file=buff)
|
||||
error = buff.getvalue()
|
||||
_logger.warning(error)
|
||||
return "failed", error
|
||||
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()
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
# Copyright (C) 2018 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class IoTDeviceAction(models.Model):
|
||||
_name = "iot.device.action"
|
||||
_description = "IoT Action"
|
||||
_order = "date_ok desc"
|
||||
|
||||
device_id = fields.Many2one("iot.device", required=True, readonly=True)
|
||||
communication_system_action_id = fields.Many2one(
|
||||
"iot.communication.system.action", required=True
|
||||
)
|
||||
status = fields.Selection(
|
||||
[("ok", "Ok"), ("pending", "Pending"), ("failed", "Failed")],
|
||||
required=True,
|
||||
default="pending",
|
||||
)
|
||||
result = fields.Text()
|
||||
date_ok = fields.Datetime(readonly=True, string="Ok date")
|
||||
|
||||
@api.constrains("device_id", "communication_system_action_id")
|
||||
def _check_system(self):
|
||||
if self.filtered(
|
||||
lambda r: r.device_id.communication_system_id
|
||||
!= r.communication_system_action_id.communication_system_id
|
||||
):
|
||||
raise ValidationError(_("Device and action must be of the same system"))
|
||||
|
||||
def run_extra_actions(self, status, result):
|
||||
return
|
||||
|
||||
def run(self):
|
||||
self.ensure_one()
|
||||
if self.status != "ok":
|
||||
status, result = self.communication_system_action_id.run(self)
|
||||
self.write(
|
||||
{
|
||||
"status": status,
|
||||
"result": result,
|
||||
"date_ok": fields.Datetime.now() if status == "ok" else False,
|
||||
}
|
||||
)
|
||||
self.run_extra_actions(status, result)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# Copyright 2021 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class IotDeviceGroup(models.Model):
|
||||
_name = "iot.device.group"
|
||||
_description = "Iot Group"
|
||||
|
||||
name = fields.Char(required=True)
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# Copyright 2021 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class IotDeviceTag(models.Model):
|
||||
|
||||
_name = "iot.device.tag"
|
||||
_description = "Device Tag"
|
||||
|
||||
name = fields.Char(required=True)
|
||||
color = fields.Integer(string="Color Index")
|
||||
Loading…
Add table
Add a link
Reference in a new issue