Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
45298 Visualizzazioni

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
Abbandona
Autore

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

Autore Risposta migliore

I have found the solution it was simply

if (field_date==False):
Avatar
Abbandona
Risposta migliore

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
Abbandona

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

Autore

thank you for your response I’ll try it

Autore

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

It does not work for me.

Risposta migliore
if variable == None:
  your code here
Avatar
Abbandona
Autore

that didn't work

Post correlati Risposte Visualizzazioni Attività
1
mar 17
28530
2
mar 16
3600
3
giu 25
838
0
mar 25
1238
1
gen 25
17772