콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
413 화면
for record in self:
if record.x_studio_export_presta == False
record.x_studio_test_computed_intero = 1
elif record.x_studio_export_presta == True
record.x_studio_test_computed_intero = 0

Could someone please help me with this computed field? I think the logic is correct, but I'm missing something in the syntax. I want the x_studio_test_computed_intero field = 1 when x_studio_export_presta is True, and if x_studio_test_computed_intero = 0 when x_studio_export_presta is False.

x_studio_export_presta is a boolean field.

아바타
취소
작성자

Sorry, maybe I expressed myself badly. I'll try to be clearer and simpler.

IF x = True, y = 1

Elseif x = False, y = 0

So,
record.x_studio_export_presta = int(record.x_studio_test_computed_intero)
?
Still don't get why you differentiate between 0/False and 1/True here, but there might be a reason for you, I suppose.

작성자 베스트 답변

Solved, Thank you

아바타
취소
베스트 답변

Hi,

Please refer to the code:

for record in self:

    if record.x_studio_export_presta:

        record.x_studio_test_computed_intero = 1

    else:

        record.x_studio_test_computed_intero = 0


Hope it helps.

아바타
취소
베스트 답변

You are probably missing the None state.

However, just

for record in self:
record.x_studio_test_computed_intero = not record.x_studio_export_presta

should be completely sufficient, because

>>> x = True
>>> y = not x
>>> print(y)
False
>>> x = False
>>> y = not x
>>> print(y)
True
>>> x = None
>>> y = not x
>>> print(y)
True



아바타
취소
관련 게시물 답글 화면 활동
1
9월 25
36
2
9월 25
367
1
9월 25
219
1
9월 25
404
2
8월 25
598