Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
3 Besvarelser
45313 Visninger

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
Kassér
Forfatter

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

Forfatter Bedste svar

I have found the solution it was simply

if (field_date==False):
Avatar
Kassér
Bedste svar

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
Kassér

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

Forfatter

thank you for your response I’ll try it

Forfatter

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

It does not work for me.

Bedste svar
if variable == None:
  your code here
Avatar
Kassér
Forfatter

that didn't work

Related Posts Besvarelser Visninger Aktivitet
1
mar. 17
28547
2
mar. 16
3619
3
jun. 25
857
0
mar. 25
1251
1
jan. 25
17785