mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-19 20: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
|
|
@ -0,0 +1 @@
|
|||
from . import iot_device_configure
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
# Copyright 2020 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from uuid import uuid4
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class IotDeviceConfigure(models.TransientModel):
|
||||
_name = "iot.device.configure"
|
||||
_description = "Configure a IoT device"
|
||||
|
||||
serial = fields.Char(readonly=True, required=True, default=lambda r: uuid4())
|
||||
url = fields.Char(compute="_compute_url")
|
||||
|
||||
@api.depends("serial")
|
||||
def _compute_url(self):
|
||||
for record in self:
|
||||
record.url = (
|
||||
self.env["ir.config_parameter"].sudo().get_param("web.base.url")
|
||||
+ "/iot/"
|
||||
+ record.serial
|
||||
+ "/configure"
|
||||
)
|
||||
|
||||
@api.model
|
||||
def configure(self, serial, template_id, ip=False, **kwargs):
|
||||
config = self.search([("serial", "=", serial)])
|
||||
if not config:
|
||||
return {}
|
||||
config.unlink()
|
||||
device = self.env["iot.device"].create({"name": serial, "ip": ip})
|
||||
template = self.env["iot.template"].search([("name", "=", template_id)])
|
||||
if template:
|
||||
template.apply_template(device, template._get_keys(serial))
|
||||
return device.get_iot_configuration()
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
Copyright 2017 Eficent Business and IT Consulting Services, S.L.
|
||||
Copyright 2017 Creu Blanca
|
||||
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
||||
-->
|
||||
<odoo>
|
||||
<record model="ir.ui.view" id="configure_form">
|
||||
<field name="name">iot.device.configure</field>
|
||||
<field name="model">iot.device.configure</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Apply template">
|
||||
<div>
|
||||
Use this URL on your device configuration
|
||||
</div>
|
||||
<group>
|
||||
<field
|
||||
name="url"
|
||||
widget="CopyClipboardChar"
|
||||
label="Configuration URL"
|
||||
/>
|
||||
</group>
|
||||
<footer>
|
||||
<button string="Close" class="btn-default" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="configure_action" model="ir.actions.server">
|
||||
<field name="name">Apply Template</field>
|
||||
<field name="model_id" ref="model_iot_device_configure" />
|
||||
<field name="state">code</field>
|
||||
<field name="code">action = model.create({}).get_formview_action()
|
||||
action["target"] = "new"</field>
|
||||
</record>
|
||||
<menuitem
|
||||
name="Add a new Device"
|
||||
sequence="1"
|
||||
id="iot_device_configuration_menu"
|
||||
action="configure_action"
|
||||
parent="iot_oca.iot_configuration_menu"
|
||||
groups="iot_oca.group_iot_manager"
|
||||
/>
|
||||
</odoo>
|
||||
Loading…
Add table
Add a link
Reference in a new issue