问题
In python, I have the following field:
'transaction_date': fields.datetime('Transaction Date')
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())]}"
/>
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?
回答1:
If you are using v7, then try this attrs:
attrs="{'invisible':[('transaction_date','!=',__import__('time').strftime('%%Y-%%m-%%d %%H:%%M:%%S'))]}"
If you are using v6 or v6.1, then try this attrs:
attrs="{'invisible':[('transaction_date','!=',time.strftime('%%Y-%%m-%%d %%H:%%M:%%S'))]}"
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.
If you will use fields.date then use time.strftime('%%Y-%%m-%%d')
in attrs.
Thank you.
来源:https://stackoverflow.com/questions/14744768/openerp-how-to-make-a-button-invisible-when-datetime-field-date-today