* 官方建议模块骨架
    --------------------------
    addons/<my_module_name>/
                 │─ __init__.py
                 │- __openerp__.py
                 │- controllers   
                 │         │- __init__.py   
                 │         │- main.py       
                 │- data
                 │     │- <main_model>_data.xml   
                 │     │- <inherited_main_model>_demo.xml
                 │            
                 │- models
                 │     │- __init__.py
                 │     │- <main_model>.py
                 │     │- <inherited_main_model>.py
                 │
                 │-    security
                 │     │- ir.model.access.csv    
                 │     │- <main_model>_security.xml
                 │
                 │-    static
                 │     │- img
                 │     │- lib
                 │     │- src
                 │     │   │- js
                 │     │   │- css
                 │     │   │- less
                 │     │   │- xml       
                 │- views
                 │     │- <main_model>_templates.xml
                 │     │- <main_model>_views.xml      
                
    文件夹权限755  文件权限644   
    __openerp__.py 相关属性:
    # name  模块名字
    # summary 简短介绍
    # description 详细描述
    # author 作者
    # website 模块网站
    # category 模块分类
    # version 模块版本号
    # license 模块版本信息 默认是 AGPL-3
    # depends 模块依赖
    # data 模块必须加载的数据文件
    # demo 示例数据
    # installabel 默认为True 可安装
    # auto_install 默认是False 如果设为True 就根据依赖模块,依赖装了,这个模块就安装
    # application 默认是 False 如果设为True 就成为应用模块
   
    安装自定义模块
        服务启动配置文件 addons-path 加入自己的定义容器目录 如 myaddons
        addons-path=addons,myaddons
        更新模块服务列表,然后找到去安装
       
    模块文件夹管理   
     # data  放 demo 和 data xml
     # models 放模型定义
     # controllers http 路径控制
     # views  放网页视图和模板
     # static 放网页的资源,里面还有css, js ,img, lib 等
     #    
   
   
    --------------------------

todo_app
     │ - security
     │       | - ir.model.access.csv
     │       | - todo_access_rules.xml
     │ - static
     │ - __init__.py
     │ - __openerp__.py
     │ - todo_model.py
     │ - todo_view.xml
   
* __init__.py 内容如下(把模型导入到应用)

from . import  todo_model

      
* __opererp__.py 内容如下(erp本身的配置)

--------------

{
   'name':'To-Do Application',
   'description': 'Manage your personal Tasks with this module.',
   'author': 'Toby Chen',
   'depends': ['mail'],
   'application': True,
   'category':'todo_app',
   'data': [
      'todo_view.xml',
      'security/ir.model.access.csv',
      'security/todo_access_rules.xml',
            ],
}

--------------

* todo_model.py 内容如下(模型)

--------------
# -*- coding: utf-8 -*-
from openerp import models,fields,api

class TodoTask(models.Model):
    _name='todo.task'
    name = fields.Char('Description', required=True)
    is_done = fields.Boolean('Done?')
    active = fields.Boolean('Active?', default=True)

    @api.one
    def do_toggle_done(self):
        self.is_done = not self.is_done
        return True

    @api.multi
    def do_clear_done(self):
        done_recs = self.search([('is_done','=','True')])
        done_recs.write({'active':False})
        return True
--------------

* todo_view.xml内容如下(视图)

--------------
<?xml version="1.0" encoding="utf-8" ?>
    <openerp>
       <data>
         <act_window /></p>               
            </t>
        </template>
    </data>
</openerp>       

上面的页面展示只有数据,不好看,可以用 website builder模块美化
__openerp__.py 加上
'depends':['website']

控制器加上
@http.route('/mymodule/mymodule', auth='public' website=True)

视图文件修改
<openerp>
    <data>
        <template id=”index”>
            <t t-call=”website.layout”>
            <t t-set=”title”>MyModule</t>
            <div class=”oe_structure”>
                <div class=”container”>
                    <t t-foreach=”fruits” t-as=”fruit”>
                    <p><t t-esc=”fruit.id”/><t t-esc=”fruit.name”></t></p>
                    </t>
                </div>
            </div>
            </t>
        </template>
    </data>
</openerp>

采用了 t-call 调用标准模板 用 t-set 设置属性值  加了oe_structrue 和 container 类


====================================

相关文章:

  • 2021-04-16
  • 2021-11-06
  • 2022-01-06
  • 2021-07-17
  • 2021-07-05
  • 2022-12-23
猜你喜欢
  • 2021-10-16
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2021-12-20
相关资源
相似解决方案