- Odoo Development Cookbook
- Holger Brunn Alexandre Fayolle Daniel Reis
- 470字
- 2021-07-16 11:00:32
Using scaffold to create a module
When creating a new Odoo module, there is some boilerplate that needs to be set up. To help quick starting new modules, Odoo provides the scaffold
command.
The recipe shows how to create a new module using the scaffold
command, which will put in place a skeleton of the files directories to use.
Getting ready
We need Odoo installed and a directory for our custom modules.
We will assume that Odoo is installed at ~/odoo-dev/odoo
and our custom modules will be at ~/odoo-dev/local-addons
.
How to do it…
The scaffold
command is used from the command line:
- Change the working directory to where we will want our module to be. This can be whatever directory you choose, but within an addons path to be useful. Following the directory choices used in the previous recipe, it should be as follows:
$ cd ~/odoo-dev/local-addons
- Choose a technical name for the new module and use the
scaffold
command to create it. For our example, we will choosemy_scaffolded
:$ ~/odoo-dev/odoo/odoo.py scaffold my_scaffolded
- Edit the
__openerp__.py
default module manifest provided and change the relevant values. You will surely want to at least change the module title in thename
key.
This is how the generated addon module should look like:
$ tree my_scaffolded my_scaffolded ├── controllers.py ├── demo.xml ├── __init__.py ├── models.py ├── __openerp__.py ├── security │ └── ir.model.access.csv └── templates.xml
How it works…
The scaffold
command creates the skeleton for a new module based on a template.
By default, the new module is created in the current working directory, but we can provide a specific directory where to create the module, passing it as an additional parameter. For example:
$ ~/odoo-dev/odoo/odoo.py scaffold my_module ~/odoo-dev/local-addons
A default
template is used but a theme
template is also available, for website theme authoring. To choose a specific template, the -t
option can be used. We are also allowed to use a path for a directory with a template.
This means that we can use our own templates with the scaffold
command. The built-in themes can be used as a guide, and they can be found in the Odoo subdirectory ./openerp/cli/templates
. To use our own template, we could use something like this:
$ ~/odoo-dev/odoo/odoo.py scaffold -t path/to/template my_module
There's more…
Unfortunately, the default template does not adhere to the current Odoo guidelines. We could create our own template by copying the default one, at odoo/openerp/cli/templates/default/
, and modifying to better suit the structure described in the Organizing the module file structure recipe. A command similar to this could get us started on that:
$ cp -r ~/odoo-dev/odoo/openerp/cli/templates/default ~/ odoo-dev/template
Later, we can use it with the following command:
$ ~/odoo-dev/odoo/odoo.py scaffold -t ~/odoo-dev/template my_module
- GeoServer Cookbook
- Cross-platform Desktop Application Development:Electron,Node,NW.js,and React
- 云原生Spring實戰(zhàn)
- HTML5+CSS3網(wǎng)站設(shè)計教程
- 鋒利的SQL(第2版)
- 你不知道的JavaScript(中卷)
- Java:High-Performance Apps with Java 9
- Vue.js 2 Web Development Projects
- 區(qū)塊鏈架構(gòu)之美:從比特幣、以太坊、超級賬本看區(qū)塊鏈架構(gòu)設(shè)計
- Oracle實用教程
- RocketMQ實戰(zhàn)與原理解析
- Unity 5 Game Optimization
- 現(xiàn)代JavaScript編程:經(jīng)典范例與實踐技巧
- 深度學(xué)習(xí):基于Python語言和TensorFlow平臺(視頻講解版)
- C++面向?qū)ο蟪绦蛟O(shè)計教程