odooodoo-10

how to disable a button after first click?


How to disable a button after clicking it in Odoo?


Solution

  • Most of Odoo module use state for this kind of problem. the general idea of it that you must have a field and the button is displayed based on the value of that field.

    Ex:

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

    In your view:

     <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"/>
    

    In your model:

     @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
        ...
        ...
        ...
    

    So if you all ready have a field that the button change it's value you can use it directly or create a special field for this purpose.