Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
45255 Zobrazení

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
Zrušit
Autor

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

Autor Nejlepší odpověď

I have found the solution it was simply

if (field_date==False):
Avatar
Zrušit
Nejlepší odpověď

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
Zrušit

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

Autor

thank you for your response I’ll try it

Autor

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

It does not work for me.

Nejlepší odpověď
if variable == None:
  your code here
Avatar
Zrušit
Autor

that didn't work

Related Posts Odpovědi Zobrazení Aktivita
1
bře 17
28489
2
bře 16
3572
3
čvn 25
793
0
bře 25
1207
1
led 25
17738