Hello. I'm a newbie to the world of programming and I still lack skills, so I need a little help. The problem is that the estado_punto field is recalculated when I navigate from the form to the tree. I don't know what could be happening. I'm using Odoo15. I would appreciate some help. Thanks in advance
class PuntoExt(models.Model):
_name = PUNTO_CONFIGS_MODEL
_inherit = PUNTO_CONFIGS_MODEL
o2m_punto_placa_exp = fields.One2many(PLACA_EXPUESTA_MODEL, 'm2o_placaexpuesta_punto',)
estado_punto = fields.Selection([
('sin_alertas', "OK"),
('una_alerta', "1 ALERTA"),
('dos_alertas', "2 ALERTAS"),
('en_limite', "LÍMITE DE ACCIÓN")
], string="Estado actual", default='sin_alertas', compute='definir_estado_punto')
@api.onchange('estado_punto')
def definir_estado_punto(self):
cont = sum(1 for i in self.o2m_punto_placa_exp[-3:] if i.cumple_alerta == 'no')
estado_dict = {
0: 'sin_alertas',
1: 'una_alerta',
2: 'dos_alertas'
}
self.estado_punto = estado_dict.get(cont, 'en_limite')
_logger.info('------------------%s' % (cont))