Unfortunately Odoo documentation doesn’t seem to include any information about adding new configuration options to Odoo. So let’s fill in the gaps.
Defining a model
First of all, you need to define a new model inheriting from res.config.settings:
It’s a TransientModel, also known as a wizard. Do not expect it to permanently hold the values. TransientModels inherently store values on a temporary basis only. You need other means to make them permanent.
Fortunately res.config.settings makes this easy. First of all, you need to add some fields to your TransientModel - one for every setting option you want to define. Odoo comes with built-in support for four different kinds of settings. It distinguishes between them based on the field names.
“Default” settings
The value of a field named default_foo will be set as a default value for a field named foo on a model given as a default_model argument.
This will make the value of default_name field the global default value of a field name in model your.other.model.
“Group” settings
Boolean fields named group_foo take two arguments: group (defaults to base.group_user) and implied_group. If the value of such field is true, the group defined in group gain all implied_group’s permissions. This is exactly the same as adding a group to implied_ids field on another group’s object (which as far as I know is also an undocumented feature). This is useful for controlling which groups of users have access to a feature.
“Module” settings
Boolean fields named module_foo, when enabled will trigger installation of a module named foo.
Other settings
By default the values of other fields will be discarded, but you change that by implementing your own means of saving them. Just define a method named set_foo (where foo is an arbitrary string). You can also set initial values of such fields using a get_default_foo method (the exact form of foo is once again irrelevant).
For example if you want to use settings to control the name and phone number of a company linked to the current user:
Defining a view
Then you just need to define a view for your settings. Let’s use the previous example:
…and of course don’t forget to make a new entry in the settings menu:
Comments
© Ludwik Trammer, 2014 — built with Jekyll using Lagom theme