Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
1365 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

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

Related Posts Odpovědi Zobrazení Aktivita
1
čvn 25
14945
3
dub 25
4941
Compute Fields Vyřešeno
2
čvc 24
1946
1
led 24
1549
2
pro 23
1277