官术网_书友最值得收藏!

  • Odoo Development Cookbook
  • Holger Brunn Alexandre Fayolle Daniel Reis
  • 464字
  • 2021-07-16 11:00:29

Storing the instance configuration in a file

The odoo.py script has dozens of options, and it is tedious to remember them all and to remember to set them properly when starting the server. Fortunately, it is possible to store them all in a configuration file and to only specify by hand the ones you want to alter, for example, for development.

How to do it...

To generate a configuration file for your Odoo instance, run the following command:

$ odoo.py --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:

$ odoo.py --help | less

This will provide you with some help about what the various options perform. To convert from the command line form to the configuration form, use the long option name, remove the leading dashes, and convert the dashes in the middle to underscores: --without-demo becomes without_demo. This works for most options, but there are a few exceptions listed in the next section.

Edit the file myodoo.cfg (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.py -c myodoo.cfg

Note

The --config option is commonly abbreviated as -c

How it works...

At start up, Odoo loads its configuration in three passes. First a set of default values for all options is initialized from the source code. Then the configuration is parsed, and any value defined in the file overrides the defaults. Finally, the command-line options are analyzed and their values override the configuration obtained from the previous pass.

As mentioned earlier, the names of the configuration variables can be found from the names of the command-line options by removing the leading dashes and converting the middle dashes to underscores. There are a few exceptions, notably:

Here is a list of options commonly set through the configuration file:

There is more...

The parsing of the configuration file by Odoo is done using the Python ConfigParser module. This module supports defining values for variables from the values of other variables using the %(section.variable)s notation. You can omit section if the value comes from the same section or if it is defined in the special [DEFAULT] section.

For instance, if you want to define the database login to be the same as the database name, you can write the following in your Odoo configuration file:

[options]
db_name = projectname
db_user = %(options.db_name)s

A very common use is to define a common prefix for the paths of the addons:

[DEFAULT]
project = /home/odoo/projects/project1
env = dev
prefix = %(project)s/%(env)s

[options]
addons-path = %(prefix)s/odoo/addons,%(prefix)s/OCA/server-tools
data_dir = %(prefix)s/data_dir
主站蜘蛛池模板: 佛学| 万安县| 桂平市| 合阳县| 长垣县| 宜城市| 漠河县| 黑水县| 阿勒泰市| 柳江县| 广平县| 滨州市| 南开区| 周宁县| 鄂托克前旗| 杂多县| 尉氏县| 贵州省| 张掖市| 黑河市| 枣阳市| 高密市| 西昌市| 龙州县| 格尔木市| 临城县| 攀枝花市| 宜兴市| 沁水县| 洪湖市| 万荣县| 夹江县| 拜泉县| 灌南县| 岑巩县| 青冈县| 堆龙德庆县| 桑日县| 伊金霍洛旗| 灵武市| 乌鲁木齐县|