mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-20 02:32:07 +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
|
|
@ -0,0 +1,4 @@
|
|||
from . import iot_device
|
||||
from . import iot_device_output_action
|
||||
from . import iot_device_output
|
||||
from . import iot_communication_system
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
# 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):
|
||||
_inherit = "iot.communication.system"
|
||||
|
||||
output_ids = fields.One2many(
|
||||
"iot.device.output", inverse_name="communication_system_id"
|
||||
)
|
||||
applies_to = fields.Selection(
|
||||
[("device", "Device"), ("output", "Output")], default="device", required=True
|
||||
)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
# 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):
|
||||
_inherit = "iot.device"
|
||||
|
||||
output_ids = fields.One2many("iot.device.output", inverse_name="device_id")
|
||||
output_count = fields.Integer(compute="_compute_output_count")
|
||||
communication_system_id = fields.Many2one(required=False)
|
||||
|
||||
@api.depends("output_ids")
|
||||
def _compute_output_count(self):
|
||||
for record in self:
|
||||
record.output_count = len(record.output_ids)
|
||||
|
||||
def action_show_output(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref("iot_output_oca.iot_device_output_action")
|
||||
result = action.read()[0]
|
||||
|
||||
result["context"] = {
|
||||
"default_device_id": self.id,
|
||||
}
|
||||
result["domain"] = "[('device_id', '=', " + str(self.id) + ")]"
|
||||
if len(self.output_ids) == 1:
|
||||
result["views"] = [(False, "form")]
|
||||
result["res_id"] = self.output_ids.id
|
||||
return result
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
# 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.output"
|
||||
_description = "IoT Device"
|
||||
|
||||
name = fields.Char(required=True)
|
||||
device_id = fields.Many2one(
|
||||
"iot.device", required=True, readonly=True, auto_join=True
|
||||
)
|
||||
communication_system_id = fields.Many2one("iot.communication.system", required=True)
|
||||
action_ids = fields.One2many("iot.device.output.action", inverse_name="output_id")
|
||||
state = fields.Selection([], readonly=True)
|
||||
model = fields.Char()
|
||||
ip = fields.Char()
|
||||
action_count = fields.Integer(compute="_compute_action_count")
|
||||
|
||||
@api.depends("action_ids")
|
||||
def _compute_action_count(self):
|
||||
for record in self:
|
||||
record.action_count = len(record.action_ids)
|
||||
|
||||
def _system_action_vals(self, system_action):
|
||||
return {
|
||||
"output_id": self.id,
|
||||
"communication_system_action_id": system_action.id,
|
||||
}
|
||||
|
||||
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:
|
||||
if not self.device_id.active:
|
||||
continue
|
||||
action = self.env["iot.device.output.action"].create(
|
||||
rec._system_action_vals(system_action)
|
||||
)
|
||||
action.run()
|
||||
self.device_id.last_contact_date = fields.Datetime.now()
|
||||
|
|
@ -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 IoTDeviceOutputAction(models.Model):
|
||||
_name = "iot.device.output.action"
|
||||
_description = "IoT Action"
|
||||
_order = "date_ok desc"
|
||||
|
||||
output_id = fields.Many2one("iot.device.output", 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("output_id", "communication_system_action_id")
|
||||
def _check_system(self):
|
||||
if self.filtered(
|
||||
lambda r: r.output_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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue