İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
45382 Görünümler

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.

Avatar
Vazgeç
Üretici

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

Üretici En İyi Yanıt

I have found the solution it was simply

if (field_date==False):
Avatar
Vazgeç
En İyi Yanı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)
Avatar
Vazgeç

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

Üretici

thank you for your response I’ll try it

Üretici

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

It does not work for me.

En İyi Yanıt
if variable == None:
  your code here
Avatar
Vazgeç
Üretici

that didn't work

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Mar 17
28607
2
Mar 16
3646
3
Haz 25
926
0
Mar 25
1295
1
Oca 25
17836