Odoo 12 Development Essentials
上QQ阅读APP看书,第一时间看更新

Adding action buttons

Forms can have buttons to perform actions. These buttons are able to run window actions such as opening another form or running Python functions defined in the model.

They can be placed anywhere inside a form, but for document-style forms, the recommended place for them is the <header> section.

For our application, we will add a field for the book ISBN, and have a button to check whether the ISBN is valid. The code for this will be in a method of the Book model. We will name it button_check_isbn().

Even though we don't have the method created yet, we can already add the corresponding button to the form:

<header> 
  <button name="button_check_isbn" type="object" 
          string="Check ISBN" /> 
</header> 

The basic attributes of a button consist of the following:

  • The string with the text to display on the button
  • The type of action it performs
  • name is the identifier for that action
  • class is an optional attribute to apply CSS styles, as in regular HTML