Odoo 12 Development Essentials
上QQ阅读APP看书,第一时间看更新

Preparing the addons path

An addons module is a directory that contains an Odoo manifest file, and provides a new app or an additional feature for an existing app. The addons module's path is a list of directories, where the Odoo server will look for available addons. By default, the addons path includes the official apps bundled with Odoo, in the odoo/addons directory, and the base module providing the core features, in the odoo/odoo/addons directory.

We should add our own modules in specific directories, whether created by us, or downloaded from the App Store or elsewhere. For the Odoo server to be able to discover them, we should add these directories to the Odoo addons paths.

Following the instructions in Chapter 2, Preparing the Development Environment, we should have the Odoo server code at ~/odoo-dev/odoo/. Best practices dictates that our code should be kept in its own directory, and never mixed up with Odoo's original code. So, to host our custom modules, we will use a new addons directory alongside Odoo, which should be included in the addons path: ~/odoo-dev/custom-addons.

To add the new addons directory to the Odoo server addons path, change the current directory, and start the server with the appropriate addons path configuration:

$ cd ~/odoo-dev
$ ./odoo/odoo-bin -d todo --addons-path="custom-addons,odoo/addons" --save

The --save option saves the options you used in a configuration file. This spares us from repeating them every time we restart the server; just run ./odoo-bin and the last saved option will be used. You can specify the configuration file and location to use (and save to) using the -c option.

Look closely at the server log. It should have an INFO ? odoo: addons paths:[...] line. It should include our custom-addons directory.

Remember to also include any other addons directories you might be using. For instance, if you have a ~/odoo-dev/extra directory that contains additional modules to be used, you might want to include them too, using the --addons-path option:

--addons-path="custom-addons,extra,odoo/addons"

Now we need the Odoo instance to acknowledge the new module we just added.

The paths used are relative to the current work directory. In configuration files, absolute paths should be used, and the --save option will do that conversion.