问题描述
在python中,我有以下字段:
In python, I have the following field:
'transaction_date': fields.datetime('Transaction Date')
在XML中,我有以下内容:
In XML, I have the following:
<field
name="transaction_date"
readonly="True"
/>
<button
name="set_void"
string="Void"
type="object"
icon="gtk-cancel"
groups="mymodule.mygroup"
attrs="{'invisible':[('transaction_date','!=', datetime.now())]}"
/>
上面的attrs代码当前不起作用,但是我想做的是:仅当transaction_date字段的日期值=今天时,才可以显示无效"按钮.有可能吗?
The attrs code above doesn't currently work but what I want to do is:be able to show the "Void" button only when the transaction_date field's date value = Today. Is that possible?
推荐答案
如果您使用的是 v7 ,请尝试以下 attrs :
If you are using v7, then try this attrs:
attrs="{'invisible':[('transaction_date','!=',__import__('time').strftime('%%Y-%%m-%%d %%H:%%M:%%S'))]}"
如果您使用的是 v6 或 v6.1 ,请尝试以下 attrs :
If you are using v6 or v6.1, then try this attrs:
attrs="{'invisible':[('transaction_date','!=',time.strftime('%%Y-%%m-%%d %%H:%%M:%%S'))]}"
我建议您使用fields.date
而不是fields.datetime
,因为您的字段将不会以 datetime 格式显示,因为只要您选择 date >& 时间,秒数将不匹配.
I would like to suggest you that you should usefields.date
instead of fields.datetime
because your field will not be visible in datetime format because whenever you will select date & time, seconds will not be match.
如果要使用 fields.date ,请在 attrs 中使用time.strftime('%%Y-%%m-%%d')
.
If you will use fields.date then use time.strftime('%%Y-%%m-%%d')
in attrs.
谢谢.
这篇关于OpenERP如何在datetime字段!=今天的日期时使按钮不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!