跳至内容
菜单
此问题已终结
1 回复
1488 查看

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


形象
丢弃
最佳答案

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​

形象
丢弃
编写者

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

相关帖文 回复 查看 活动
1
6月 25
15188
3
4月 25
5300
2
7月 24
2178
1
1月 24
1684
2
12月 23
1373