콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
1391 화면

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
14996
3
4월 25
5023
Compute Fields 해결 완료
2
7월 24
1969
1
1월 24
1575
2
12월 23
1302