Button
Simple button
<button type="object" name="a_method" string="A simple button" />
A simple button
Button with icon
<button type="object" name="a_method" string="A simple button" icon="gtk-execute" />
Primary button
<button type="object" name="a_method" string="A simple button" icon="gtk-execute" primary="1" />
Danger button
<button type="object" name="a_method" string="A simple button" icon="gtk-execute" danger="1" />
Primary danger button
<button type="object" name="a_method" string="A simple button" icon="gtk-execute" primary="1" danger="1" />
Confirm button
<button type="object" name="a_method" string="A simple button" icon="gtk-execute" confirm="Are you sure?" />
Calling actions
There are three ways to call actions on the server, configured according to the type
of the button and the name
.
-
workflow: Calls a workflow type action. The
name
is the signal that will be called. -
action: Calls an action type action (known as wizards) and in the name, we must put the XML identifier of the action. For example, with the action defined in the
giscemisc_monitor
module with identifieraction_wizard_monitor_ping
:<record id="action_wizard_monitor_ping" model="ir.actions.act_window"><field name="name">Ping</field><field name="type">ir.actions.act_window</field><field name="res_model">wizard.monitor.ping</field><field name="view_type">form</field><field name="view_mode">form</field><field name="target">new</field></record><button string="Ping MOXA" type="action"name="%(giscemisc_monitor.action_wizard_monitor_ping)d" />
- object: Calls an object type action. The
name
is the method that will be called. and as parameters, it will pass the object’s id and the context.
For example, to call the action_method
method of the res.partner
object:
<button string="Action method" type="object" name="action_method" />
And the action_method
method of the res.partner
object:
def action_method(self, cursor, uid, ids, context=None): if context is None: context = {} # Do something
API
Property | Description | Type | Default | Version |
---|---|---|---|---|
type | Type of button | workflow | action | object | cancel | workflow | - |
icon | Icon for the button. See Icons | string | - | - |
string | Text for the button | string | - | - |
confirm | Message to ask for a confirmation from user | string | - | - |
primary | Format as a primary button. Fill the button with primary color | 1 | 0 | - | - |
danger | Mark this button as danger color, can be used with primary to fill the background | 1 | 0 | - | - |
name | Action to call. See Calling actions | string | - | - |
context | Context to send to the server | dict | - | - |