如何在第一次点击后禁用按钮?

问题描述 投票:0回答:1

如何在 Odoo 中单击按钮后禁用该按钮?

odoo odoo-10
1个回答
5
投票

大多数 Odoo 模块都使用状态来解决此类问题。它的总体思路是您必须有一个字段,并且按钮是根据该字段的值显示的。

例如:

  # in you model
  bool_field = fields.Boolean('Same text', default=False)

您认为:

 <button name="some_method"......... attrs="{'invisible': [('bool_field', '=', True)]}" />
 ...
 ...
 ...
 <!-- keep the field invisible because i don't need the user to see
      it, the value of this field is for technical purpuse -->
 <field name="bool_field" invisible="1"/>

在您的模型中:

 @api.multi
 def some_method(self):
    # in this method i will make sure to change the value of the 
    # field to True so the button is not visible any more for user
    self.bool_field = True
    ...
    ...
    ...

因此,如果您准备好一个字段,按钮可以更改其值,您可以直接使用它 或为此目的创建一个特殊字段。

© www.soinside.com 2019 - 2024. All rights reserved.