Storing the instance configuration in a file
The odoo-bin
script has dozens of options, and it is tedious to remember them all, as well as how to remember to set them properly when starting the server. Fortunately, it is possible to store them all in a configuration file and only specify the ones you want to alter for development, for example.
How to do it...
For this recipe, perform the following steps:
- To generate a configuration file for your Odoo instance, run the following command:
$ ./odoo-bin --save --config myodoo.cfg --stop-after-init
- You can add additional options, and their values will be saved in the generated file. All the unset options will be saved with their default value set. To get a list of possible options, use the following command:
$ ./odoo-bin --help | less
This will provide you with some help about what the various options perform.
- To convert from the command-line form into the configuration form, use the long option name, remove the leading dashes, and convert the dashes in the middle into underscores. So, in this case,
--without-demo
will becomewithout_demo
. This works for most options, but there are a few exceptions, all of which are listed in the following section. - Edit the
myodoo.cfg
file (use the table in the following section for some parameters you may want to change). Then, to start the server with the saved options, run the following command:$ ./odoo-bin -c myodoo.cfg
Note
The --config
option is commonly abbreviated as -c
.
How it works...
At startup, Odoo loads its configuration in three passes. First, a set of default values for all options is initialized from the source code. After, the configuration is parsed, and then any value that’s defined in the file overrides the defaults. Finally, the command-line options are analyzed, and their values override the configuration that was obtained from the previous pass.
As we mentioned earlier, the names of the configuration variables can be found by looking at the names of the command-line options by removing the leading dashes and converting the middle dashes into underscores. There are a few exceptions to this, notably the following:
Table 1.1 – Difference in Odoo parameters regarding the command line and the configuration file
Here’s a list of options that are commonly set through the configuration file:
Table 1.2 – Odoo parameters and their usage
Here’s a list of configuration options related to the database:
Table 1.3 – Odoo parameters and their usage
The configuration file is parsed by Odoo using the Python ConfigParser
module. However, the implementation in Odoo 11.0 has changed, and it is no longer possible to use variable interpolation. So, if you are used to defining values for variables from the values of other variables using the %(section.variable)s
notation, you will need to change your habits and revert to explicit values.
Some options are not used in config files, but they are widely used during development:
Table 1.4 – Odoo parameters and their usage