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

Configuring the addons path

The addons path is a configuration parameter that lists the directories, which will be searched for addon modules by Odoo when it initializes a new database.

Directories listed in the addons path are expected to contain subdirectories, each of which is an addon module.

Getting ready

This recipe assumes you have an instance ready, with a configuration file generated as described in Chapter 1, Installing the Odoo Development Environment. The source code of Odoo is available in ~/odoo-dev/odoo, and the configuration file is in ~/odoo-dev/my-instance.cfg.

How to do it…

To add the directory ~/odoo-dev/local-addons to the addons path of the instance, follow these steps:

  1. Edit the configuration file for your instance ~/odoo-dev/my-instance.cfg
  2. Locate the line starting with addons_path =. By default, it should look like the following:
    addons_path = ~/odoo-dev/odoo/openerp/addons,~/odoo-dev/odoo/addons
    
  3. Modify the line by appending a comma followed by the name of the directory you want to add to the addons path:
    addons_path = ~/odoo-dev/odoo/openerp/addons,~/odoo-dev/odoo/addons,~/odoo-dev/local-addons
    

    You can tidy that line a little by adding a root variable and using it to shorten the path definition (see Chapter 1, Installing the Odoo Development Environment, for more on this):

    root = ~/odoo-dev
    addons_path = %(root)s/odoo/openerp/addons,%(root)s/odoo/addons,%(root)s/local-addons
    
  4. Restart your instance:
    $ ~/odoo-dev/odoo/odoo.py -c my-instance.cfg
    

How it works…

When Odoo is restarted, the configuration file is read. The value of the addons_path variable is expected to be a comma-separated list of directories. Relative paths are accepted, but they are relative to the current working directory, and therefore should be avoided in the configuration file.

At this point, the new addons present in ~/odoo-dev/local-addons are not available in the list of available addon modules of the instance. For this, you need to perform an extra operation explained in the next recipe, Updating the addon modules list.

There's more…

When you call the odoo.py script for the first time to initialize a new database, you can pass the --addons-path command line argument with a comma-separated list of directories. This will initialize the list of available addon modules with all the addons found in the supplied addons path. When you do this, you have to explicitly include the base addons directory (odoo/openerp/addons) as well as the core addons directory (odoo/addons). Be careful—if you put a space after the commas—you will need to quote the list of directories. You can use the --save option to also save the path to the configuration file:

$ odoo/odoo.py -d mydatabase \
--addons-path="odoo/openerp/addons,odoo/addons,local-addons" \
--save -c odoo-project.cfg –stop-after-init

In this case, using relative paths is OK, since they will be converted to absolute paths in the configuration file.

主站蜘蛛池模板: 贵阳市| 泰来县| 佛教| 霍邱县| 江孜县| 绍兴县| 巴楚县| 巴中市| 尉犁县| 大埔县| 金寨县| 抚州市| 邓州市| 鲜城| 西乌珠穆沁旗| 庆城县| 临猗县| 清流县| 政和县| 福清市| 崇义县| 信阳市| 蓬溪县| 抚宁县| 辽宁省| 兴宁市| 江陵县| 江油市| 黎川县| 乳山市| 察哈| 历史| 华蓥市| 宁蒗| 平阴县| 商城县| 汤阴县| 五华县| 秦安县| 公安县| 新泰市|