Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
3 Ответы
45446 Представления

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
28661
2
мар. 16
3673
3
июн. 25
1036
0
мар. 25
1367
1
янв. 25
17939