Adding Buttons and Actions to an Odoo View

A button on a view lets a user trigger something. How a developer adds buttons and actions.

A view shows a record, but a user often needs to do something from it, trigger an action. Buttons are how. This piece is about adding buttons and actions to an Odoo view.

Why a view needs buttons

A view, a form view in particular, presents a record for the user to see and edit. But working with a record is often not only viewing and editing its fields; it is also doing things, triggering some action that should happen in connection with the record. The user needs a way, from the view, to trigger that action, and a button is that way: a button on the view that the user can use to trigger something.

Buttons and the actions they trigger

A button on a view is a trigger; what it triggers is an action, something that genuinely happens when the button is used. The button is the means the user has to set the action off; the action is the thing that genuinely occurs. Adding buttons and actions to a view is, then, two connected things: adding the button, the trigger on the view, and providing the action, what genuinely happens when the button is used. The button without a genuine action does nothing; the action without a button has no way for the user to trigger it. The two go together.

Adding a button to a view

A developer adds a button to a view as part of the view's definition, so the button appears on the view for the user. And, since adding a button is often a change to an existing view, this is commonly done through view inheritance, the inheriting view adding the button to the existing view, cleanly, rather than the view being rewritten. So adding a button is, often, an instance of extending a view through inheritance: the developer's change to the view is the addition of the button.

Providing the action

Adding the button is half of it; the other half is providing the action the button triggers, so that, when the user uses the button, something genuine and intended happens. The action is the genuine behaviour: the logic, the thing that should occur in connection with the record. A developer adding a button has to provide that genuine action, so the button is a real, working trigger and not an empty one. Adding buttons and actions well means the button is there for the user and the action it triggers is the genuine, intended behaviour.

Add buttons for genuine actions

An honest note. A button on a view should be there to let the user trigger a genuine, useful action, something the user genuinely needs to be able to do from the view. A developer should add buttons for genuine actions, so each button on a view has a real purpose. A view cluttered with buttons that do little adds confusion; a view with the buttons users genuinely need, for genuine actions, helps them. Add buttons and actions for the genuine things users need to do from the view.

The takeaway

Adding buttons and actions to an Odoo view gives users a way to trigger an action from a view: the button is the trigger on the view, the action is what genuinely happens when it is used, and the two go together. A developer adds a button as part of the view's definition, often through view inheritance, extending an existing view cleanly, and provides the genuine action the button triggers. Add buttons for genuine, useful actions users need to do from the view, so each button has a real purpose. For how we approach Odoo, see our ERP practice.

All posts

Got a Topic Worth Posting?

Suggest a Topic

If a question keeps coming up in your operations, it might be worth its own post.