OpenERP How to make a button invisible when dateti

2019-06-01 20:37发布

问题:

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.



标签: xml openerp