跳至内容
菜单
此问题已终结
3 回复
45236 查看

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

相关帖文 回复 查看 活动
1
3月 17
28469
2
3月 16
3559
3
6月 25
777
0
3月 25
1193
1
1月 25
17721