Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
1482 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

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

Post Terkait Replies Tampilan Aktivitas
1
Jun 25
15163
3
Apr 25
5260
Compute Fields Diselesaikan
2
Jul 24
2129
1
Jan 24
1658
2
Des 23
1361