How it works...

The first XML element, act_window, declares a window action to display a list view with all the customers. We used the most important attributes:

  • name: To be used as the title for views opened by the action.
  • res_model: This is the model to be used. We are using res.partner, where Odoo stores all the partners and addresses, including customers.
  • view_mode: This lists the view types to make available. It is a comma separated values of type of views. The default value is list, form, which makes list and form views available. If you just want to show calendar and form view then the value of view_mode will be calendar, form. Other possible view choices are kanban, graph, pivot, calendar, cohort, and dashboard. You will learn more about these views in forthcoming recipes.
  • domain: This is optional and allows you to set a filter on the records to be made available in the views. In this case, we want to limit the partners to only those who are customers. We will see all of these view in more detail in the Defining filters on record lists – Domain recipe of this chapter.
  • context: This can set values made available to the opened views, affecting their behavior. In our example, on new records, we want the customer flag's default value to be True. This will be covered in more depth in Passing parameters to forms and actions – Context recipe of this chapter.
  • limit: This sets the default amount of records that can be seen on list views. It defaults to 80.
In legacy code, you'll find the view mode tree quite often. This was the internal name of list views up to and including Odoo 11. Version 12 still accepts this value, but treats it as if you had written list.

Next, we create the menu item hierarchy from the top-level menu to the clickable end menu item. The most important attributes for the menuitem element are as follows:

  • name: This is used as the text the menu items display. If your menu item links to an action, you can leave this out, because the action's name will be used in that case.
  • parent (parent_id if using the record element): This is the XML ID that references the parent menu item. Items with no parents are top-level menus.
  • action: This is the XML ID that references the action to be called.
  • sequence: This is used to order the sibling menu items.
  • groups (groups_id with the record tag): This is an optional list of user groups that can access the menu item. If empty, it will be available to all users.
  • web_icon: This option only works on the top-level menu. It will display an icon of your application in the Enterprise edition.

Window actions automatically determine the view to be used by looking up views for the target model with the intended type (form, tree, and so on) and picking the one with the lowest sequence number.

act_window and menuitem are convenient shortcut XML tags that hide what you're actually doing. If you don't want to use the shortcut XML tags then you can create a record of the ir.actions.act_window and ir.ui.menu models via the <record> tag . For example, if you want to load act_window with <record>, you can do so as follows:

<record id='action_all_customers' model='ir.actions.act_window'>
<field name="name">All customers</field>
<field name="res_model">res.partner</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('customer', '=', True)]</field>
<field name="context">{'default_customer': True}</field>
<field name="limit">20</field>
</record>

In the same way, you can create a menuitem through <record>.

Be aware that names used with the menuitem shortcut may not map to the field names that are used when using a record element parent should be parent_id and groups should be groups_id.

To build the menu, the web client reads all the records from ir.ui.menu and infers their hierarchy from the parent_id field. Menus are also filtered based on user permissions to models and groups assigned to menus and actions. When a user clicks on a menu item, its action is executed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset