跳至內容
選單
此問題已被標幟
1 回覆
1378 瀏覽次數

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
14968
3
4月 25
4983
2
7月 24
1956
1
1月 24
1567
2
12月 23
1290