Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
3 Antwoorden
45453 Weergaven

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
Annuleer
Auteur

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

Auteur Beste antwoord

I have found the solution it was simply

if (field_date==False):
Avatar
Annuleer
Beste antwoord

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
Annuleer

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

Auteur

thank you for your response I’ll try it

Auteur

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

It does not work for me.

Beste antwoord
if variable == None:
  your code here
Avatar
Annuleer
Auteur

that didn't work

Gerelateerde posts Antwoorden Weergaven Activiteit
1
mrt. 17
28667
2
mrt. 16
3676
3
jun. 25
1041
0
mrt. 25
1372
1
jan. 25
17942