如何根据时间odoo12隐藏或赋予按钮属性?

How to hide or give attributes to the button based on time odoo12?

我在表单视图中有一个日期时间字段,在表单视图中我需要根据时间隐藏按钮。(比如日期时间字段中的时间前一小时)

您可以使用此方法。

在您各自的模型中添加 compute 布尔字段。

例如:

class InheritSaleOrder(models.Model):
    _inherit = 'sale.order'

    show_hide_button = fields.Boolean(compute='_get_visible')
    
    def _get_visible(self):
        //Here you can write your code
        if YOUR_LOGIC:
           self.show_hide_button = True
        else:
           self.show_hide_button = False

在XML中:

<field name="show_hide_button" invisible="1"/>
<button name="your_button" type="object" attrs="{'invisible': [('show_hide_button', '=', False)]}"/>
                               

其次你可以使用@api.onchange让它根据时间隐藏和可见。