A Window Action gives instructions to the GUI client and is usually used by menu items or buttons in views. It tells the GUI which model to work on and which views to make available. These actions can filter the records to be available, using a domain filter, and can set default values and filters through the context attribute.
Window Actions are stored in the ir.actions.act_window model and can be browsed via the Settings | Technical | Actions | Window Actions menu.
In library_checkout/views/library_menu.xml, we can find the Window Action used in the checkout menu item. We need to make a change to it to enable the additional view types we'll add in this chapter:
<act_window id="action_library_checkout"
name="Checkouts"
res_model="library.checkout"
view_mode="tree,form,activity,calendar,graph,pivot"
/>
Window Actions are usually created using the <act_window> shortcut, used previously. We're changing view_mode from "tree, form" to the larger "tree,form,activity,calendar,graph,pivot" list.
The Window Action attributes used are as follows:
- name is the title that will be displayed on the views opened through this action.
- res_model is the identifier of the target model.
- view_mode is a comma-separated list of the view types to make available. The first in the list is the one to open by default.
Other Window Action attributes are the following:
- target, if set to new, will open the view in a pop-up dialog window, for example, target="new". By default, it's current, opening the view inline in the main content area.
- context sets context information on the target views, which can set default values or activate filters, among other things, for example, context="{'default_user_id': uid}".
- domain is a domain expression forcing a filter for the records that can be browsed in the opened views, for example,domain="[('user_id', '=', uid)]".
- limit is the number of records for each page, in the list view, for example,limit="80".
After these changes are installed, when you select the Checkouts menu item and navigate to the corresponding list view, there will be additional buttons in the top-right corner, after the list and form buttons. However, these won't work until we create the corresponding views, which we'll cover later in this chapter.
Window Actions can also be used from the Action menu button, available at the top of the list and form views, next to the Filters button. For this, we need to add two more attributes to the <act_window> element:
- src_model sets the model where the action will be made available, for example, src_model="library.checkout".
- multi="true" enables the action on the list view also, so that it can work on multiple selected records. Otherwise, it's available only in the form view, and can only be applied to one record at a time.