تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
45395 أدوات العرض

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
مارس 17
28616
2
مارس 16
3650
3
يونيو 25
964
0
مارس 25
1308
1
يناير 25
17855