- Odoo 11 Development Cookbook(Second Edition)
- Holger Brunn Alexandre Fayolle
- 258字
- 2021-06-25 22:48:40
How to do it...
The following steps will create and install a new addon module:
- Change the working directory in which we will work and create the addons directory where our custom module will be placed:
$ cd ~/odoo-dev $ mkdir local-addons
- Choose a technical name for the new module and create a directory with that name for the module. For our example, we will use my_module:
$ mkdir local-addons/my_module
A module's technical name must be a valid Python identifier; it must begin with a letter, and only contain letters (preferably lowercase), numbers, and underscore characters.
- Make the Python module importable by adding an __init__.py file:
$ touch local-addons/my_module/__init__.py
- Add a minimal module manifest for Odoo to detect it. Create a __manifest__.py file with this line:
{'name': 'My module'}
- Start your Odoo instance including our module directory in the addons path:
$ odoo/odoo-bin --addons-path=odoo/addon/,local-addons/
If the --save option is added to the Odoo command, the addons path will be saved in the configuration file. Next time you start the server, if no addons path option is provided, this will be used.
- Make the new module available in your Odoo instance; log in to Odoo using admin, enable the Developer Mode in the About box, and in the Apps top menu, select Update Apps List. Now, Odoo should know about our Odoo module.
- Select the Apps menu at the top and, in the search bar in the top-right, delete the default Apps filter and search for my_module. Click on its Install button, and the installation will be concluded.