Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
1483 มุมมอง

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.

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มิ.ย. 25
15167
3
เม.ย. 25
5266
Compute Fields แก้ไขแล้ว
2
ก.ค. 24
2140
1
ม.ค. 24
1665
GDPR checkbox for landing page แก้ไขแล้ว
2
ธ.ค. 23
1361