configuracion.py 1.17 KB
# -*- coding: utf-8 -*-
from odoo.exceptions import UserError
from odoo import models, fields, api
import requests, time
class hgt_coniguracion_incidencias(models.Model):
    _name = 'hgt.coniguracion_incidencias'
    _order = "id desc"

    habilitado = fields.Boolean(string='Habilitado', default=False)
    name = fields.Char(string='Nombre de perfil')
    dispacher = fields.Many2one(comodel_name='res.users', string='Dispacher')
    url_ost = fields.Boolean(string='Agregar url a bitacora')

    @api.onchange('habilitado')
    def _onchange_habilitado(self):
        configs = self.env['hgt.coniguracion_incidencias'].search([["id", "!=", self._origin.id], ["habilitado", "=", True]])
        if (self.habilitado ==  False) and (len(configs) == 0):
            self.habilitado =  True
        if self.habilitado ==  True:
            for conf in configs:
                conf.write({"habilitado": False})

    def confirm(self):
        print(self.id)
        self.habilitado =  True
        configs = self.env['hgt.coniguracion_incidencias'].search([["id", "!=", self.id], ["habilitado", "=", True]])
        for conf in configs:
            conf.write({"habilitado": False})