Skip to Content
Menu
This question has been flagged
3 Replies
45469 Rodiniai

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.

Portretas
Atmesti
Autorius

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

Autorius Best Answer

I have found the solution it was simply

if (field_date==False):
Portretas
Atmesti
Best Answer

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)
Portretas
Atmesti

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

Autorius

thank you for your response I’ll try it

Autorius

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

It does not work for me.

Best Answer
if variable == None:
  your code here
Portretas
Atmesti
Autorius

that didn't work

Related Posts Replies Rodiniai Veikla
1
kov. 17
28674
2
kov. 16
3681
3
birž. 25
1055
0
kov. 25
1375
1
saus. 25
17947