我在表单视图中有一个日期时间字段,在表单视图中我需要根据时间隐藏按钮。(例如,在日期时间字段中的时间之前一个小时)
答案 0 :(得分:1)
您可以使用此方法。
在各个模型中,添加 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
使它根据时间隐藏和显示。