How it works...

In Odoo, all settings options are added in the res.config.settings model. res.config.settings is a transient model. In step 1, we created a new security group. We will use this group to create the hide and show buttons.

In step 2, we added a new Boolean field in the res.config.settings model by inheriting it. We added an implied_group attribute with the value of my_library.group_self_borrow. This group will be assigned to all odoo users when the admin enables or disables options with the Boolean field.

Odoo settings use a form view to display settings options on a user interface. All of these options are added in a single form view with the external ID, base.res_config_settings_view_form. In step 3, we added our option in the user interface by inheriting this setting form view. We used xpath to add our setting option. In Chapter 10, Backend Views, we will see this in detail. In the form definition, you will find that the attribute data-key value of this option will be your module name. This is only needed when you are adding a whole new tab in Settings. Otherwise, you can just add your option in the Settings tab of the existing module with xpath.

In step 4, we added an action and a menu to access the configuration options from the user interface. You will need to pass the {'module' : 'my_library'} context from the action to open the Settings tab of the my_library module by default when the menu is clicked.

In step 5, we added my_library.group_self_borrow groups to the buttons. Because of this group, the Borrow and Return buttons will be hidden or shown, based on the settings options.

After this, you will see a separate Settings tab for the library, and, in the tab, you will see a Boolean field to enable or disable the self-borrowing option. When you enable or disable this option, in the background, Odoo will apply or remove the implied_group to or from all odoo users. Because we added the groups on buttons, the buttons will be displayed if the user has groups and will be hidden if the user doesn't have groups. In Chapter 11, Access Security, we will look at security groups in detail.

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

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