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

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:

  1. 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
    
  2. Choose a technical name for the new module and use the scaffold command to create it. For our example, we will choose my_scaffolded:
    $ ~/odoo-dev/odoo/odoo.py scaffold my_scaffolded
    
  3. 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 the name 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
主站蜘蛛池模板: 东乡族自治县| 泗阳县| 隆林| 乌拉特后旗| 瓦房店市| 平阴县| 洛南县| 辽阳市| 乌兰县| 鸡西市| 九龙城区| 木兰县| 洪雅县| 林甸县| 进贤县| 南雄市| 怀远县| 谷城县| 昭觉县| 宜宾县| 遵义县| 内江市| 府谷县| 彩票| 贵德县| 安龙县| 天气| 正安县| 万年县| 临西县| 彰化市| 桐庐县| 凉山| 宁明县| 诏安县| 化州市| 体育| 乐昌市| 临泽县| 鞍山市| 鹤峰县|