Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
45331 Переглядів

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.

Аватар
Відмінити
Автор

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

Автор Найкраща відповідь

I have found the solution it was simply

if (field_date==False):
Аватар
Відмінити
Найкраща відповідь

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)
Аватар
Відмінити

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

Автор

thank you for your response I’ll try it

Автор

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

It does not work for me.

Найкраща відповідь
if variable == None:
  your code here
Аватар
Відмінити
Автор

that didn't work

Related Posts Відповіді Переглядів Дія
1
бер. 17
28564
2
бер. 16
3628
3
черв. 25
869
0
бер. 25
1263
1
січ. 25
17798