上一节说了怎么创建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,
}
#重启服务并更新模块