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

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
主站蜘蛛池模板: 陵川县| 开平市| 广宗县| 山西省| 忻州市| 万荣县| 临洮县| 渝中区| 泸定县| 宜阳县| 潞西市| 天台县| 卓资县| 耿马| 禄丰县| 鸡泽县| 札达县| 依安县| 宿松县| 通江县| 铜陵市| 泸定县| 大新县| 长武县| 锡林郭勒盟| 土默特左旗| 马关县| 兴安县| 贵南县| 滨海县| 常德市| 墨竹工卡县| 天津市| 临夏市| 石渠县| 汕尾市| 临颍县| 宜昌市| 定陶县| 开封市| 呼伦贝尔市|