Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
3 Vastaukset
45032 Näkymät

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
Hylkää
Tekijä

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

Tekijä Paras vastaus

I have found the solution it was simply

if (field_date==False):
Avatar
Hylkää
Paras vastaus

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
Hylkää

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

Tekijä

thank you for your response I’ll try it

Tekijä

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

It does not work for me.

Paras vastaus
if variable == None:
  your code here
Avatar
Hylkää
Tekijä

that didn't work

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
maalisk. 17
28282
2
maalisk. 16
3436
3
kesäk. 25
454
0
maalisk. 25
971
1
tammik. 25
17463