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

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 17
28673
2
มี.ค. 16
3676
3
มิ.ย. 25
1050
0
มี.ค. 25
1374
1
ม.ค. 25
17945