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

Hello, I want to make a condition if the value of a field date is null then I'll do some treatments in python code. Thank you.

아바타
취소
작성자

I have found the solution it was simply if (field_date==False):

작성자 베스트 답변

I have found the solution it was simply

if (field_date==False):
아바타
취소
베스트 답변

maybe like this :

def create(self, cr, uid, vals, context=None):
    if not vals['field_date']: # field_date is null/not set
        vals['field_date'] = time.strftime('%Y-%m-%d')
    return super(scale_material, self).create(cr, uid, vals, context=context)
아바타
취소

This will throw a key error if field_date is not in vals. You could either do if not vals.get('field_date', False): or if not 'field_date' in vals and not vals['field_date']: Also don't forget the write method as well.

thank you for more explation

작성자

thank you for your response I’ll try it

작성자

I have found the solution it was simply if (field_date==False):

It does not work for me.

베스트 답변
if variable == None:
  your code here
아바타
취소
작성자

that didn't work

관련 게시물 답글 화면 활동
1
3월 17
28791
2
3월 16
3759
3
6월 25
1188
0
3월 25
1521
1
1월 25
18027