OpenERP How to make a button invisible when datetime field != date today

若如初见. 提交于 2019-12-08 06:24:02

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!