Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1246 Vistas

In my model, there is a compute field A, it is computed from 2 number fields B and C and 1 checkbox field D. My wanted compute code is like below:

 

Dependencies: B, C, D


Code:


for record in self:

    if record.D == True:

        record['A'] = record.B + record.C

    else:

        record['A'] = record.B

 

How do I write "if record.D == True" correctly? It doesn’t work now.

 

Thanks


Avatar
Descartar
Mejor respuesta

This should work:

A = fields.Integer(compute="_compute_A")

@api.depends("B","C","D")
def _compute_A(self):
​for record in self:
​if record.D:
​record.A = record.B + record.C
​else:
record.a = record.B​

Avatar
Descartar
Autor

Hi, I know what happens now. When I click D, I have to click the 'Save manually' button for A to update.

Publicaciones relacionadas Respuestas Vistas Actividad
3
abr 25
4298
2
jul 24
1592
1
ene 24
1251
2
dic 23
1111
1
jul 22
1743