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

  • 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:

  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
主站蜘蛛池模板: 阿城市| 闽清县| 龙门县| 福州市| 江山市| 瑞安市| 莱西市| 江阴市| 阿拉善左旗| 琼海市| 奉新县| 西吉县| 琼中| 股票| 犍为县| 长乐市| 衡山县| 武陟县| 泸水县| 兰州市| 乌拉特中旗| 仪陇县| 阳春市| 大丰市| 榕江县| 美姑县| 梁平县| 政和县| 平山县| 常宁市| 南安市| 贡觉县| 南华县| 镇赉县| 德阳市| 大关县| 德格县| 望都县| 甘泉县| 阆中市| 平乐县|