Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
45459 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Tác giả Câu trả lời hay nhất

I have found the solution it was simply

if (field_date==False):
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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)
Ảnh đại diện
Huỷ bỏ

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

Tác giả

thank you for your response I’ll try it

Tác giả

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

It does not work for me.

Câu trả lời hay nhất
if variable == None:
  your code here
Ảnh đại diện
Huỷ bỏ
Tác giả

that didn't work

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 17
28673
2
thg 3 16
3677
3
thg 6 25
1051
0
thg 3 25
1375
1
thg 1 25
17946