- Odoo Development Cookbook
- Holger Brunn Alexandre Fayolle Daniel Reis
- 437字
- 2021-07-16 11:00:30
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:
- Edit the configuration file for your instance
~/odoo-dev/my-instance.cfg
- 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
- 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
- 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.
- 案例式C語言程序設(shè)計
- 工程軟件開發(fā)技術(shù)基礎(chǔ)
- Python for Secret Agents:Volume II
- 編寫高質(zhì)量代碼:改善Python程序的91個建議
- Production Ready OpenStack:Recipes for Successful Environments
- 琢石成器:Windows環(huán)境下32位匯編語言程序設(shè)計
- Visual C#.NET程序設(shè)計
- 劍指大數(shù)據(jù):企業(yè)級數(shù)據(jù)倉庫項目實戰(zhàn)(在線教育版)
- C++ Application Development with Code:Blocks
- HTML+CSS+JavaScript網(wǎng)頁制作:從入門到精通(第4版)
- Kotlin進階實戰(zhàn)
- Python硬件編程實戰(zhàn)
- DB2SQL性能調(diào)優(yōu)秘笈
- Python編程入門(第3版)
- SQL Server on Linux