We added a button in the previous form, but there are quite different types of buttons to use. This recipe will add another button; also put the following code in to the previous recipe's header
element.
Add a button referring to an action:
<button type="action" name="%(base.action_partner_category_form)d" string="Open partner categories" />
The button's type attribute determines the semantics of the other fields, so we'll first look into the possible values:
action
: This makes the button call an action as defined in the ir.actions.* namespace. The name
attribute needs to contain the action's database id, which you can conveniently look up with a python format string containing the XML ID of the action in question.object
: This calls a method of the current model. The name
attribute contains the function's name. The function should have the signature @api.multi
and will act on the currently viewed record.workflow
: This sends a workflow signal to the current record. The name
attribute needs to contain the signal's name. Use the states
attribute to make the workflow buttons only available in states where they actually do something, that is, in states that have transitions triggered by the signal in question.The string
attribute is used to assign the text the user sees.
Use CSS classes btn-primary
to render a button that is highlighted (currently blue) and btn-default
to render a normal button. This is commonly used for the cancel buttons in wizards or to offer secondary actions in a visually unobtrusive way.
The call with a button of type object can return a dictionary describing an action, which will then be executed on the client side. This way you can implement multi screen wizards or just open some other record.
You can also have content within the button
tag, replacing the string
attribute. This is commonly used in button boxes as described in the recipe Document style forms.