Odoo开发教程(四):定义Tree-Form-Menu-Action

        上一节说了怎么创建ORM,有了ORM以后我们能在数据字典定义里面看到我们创建的类,但是UI还没有,所以作为数据库系统,我们需要有各类按钮跟表单!

本节更详细内容请看官方:https://www.odoo.com/documentation/9.0/reference/actions.html,我们这里讲的是9.0的新方法!

        我们在项目里面单独创建一个views目录用来存放所有有关view方面的定义文件,然后再创建一个myfirstview.xml文件用来定义,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <!--以下定义action,action要跟menu关联,并且定义要在menuitem以前,如果menu跟action在不同的-->
    <!--文件中定义,在__openerp__.py的data参数中要把定义action的文件写在前面,不然系统会找不到action id-->
    <!--这里具体的内容看最前面说的官方地址有详细说明-->
    <record id="myfirst_action" model="ir.actions.act_window">
        <field name="name">myfirst action</field>
        <field name="res_model">myfirst.expense</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">
                Click here to create new record.
            </p>
            <p>
            Once you have created your expense, submit it to your manager who will validate it.
        </p>
        </field>
    </record>

    <!--form表单的定义-->
    <record id="myfirst_form_view" model="ir.ui.view">
        <field name="name">myfirst.form</field>
        <field name="model">myfirst.expense</field>
        <field eval="25" name="priority"/>
        <field name="arch" type="xml">
            <form string="myfirt form">
                <field name="description"/>
            </form>
        </field>
    </record>
    
    <!--tree表单的定义-->
    <record id="myfirst_tree" model="ir.ui.view">
       <field name="name">myfirst.tree</field>
       <field name="model">myfirst.expense</field>
       <field name="arch" type="xml">
          <tree string="myfirst tree">
             <field name="description"/>
          </tree>
       </field>
    </record>

    
    <!--menu的定义,指向哪个action要在这里定义-->
    <menuitem id="myfirst_root_menu" name="myfirst"/>
    <menuitem id="myfirst_menu" name="myfirstmenu" parent="myfirst_root_menu" action="myfirst.myfirst_action"/>

</odoo>

__openerp__.py文件中关联这个定义文件

# -*- coding: utf-8 -*-
{
    'name': 'myfirst',
    'version': '0.1',
    'author': 'feigames',
    'description': """
模块说明
""",
    'depends': [
        'base',
        'mail',
    ],
    'data': [
      'views/myfirstview.xml',  #view的定义文件
    ],
    'installable': True,
    'application': True,
}


#重启服务并更新模块




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值