Design Elements
文件中的视图描述形式如下:
Example: |
---|
<?xml version="1.0"?>
<openerp>
<data>
[view definitions]
</data>
</openerp>
视图定义包含了以下三种类型的标签:
标签有属性model=“ir.ui.view”,它包含本身的视图定义
标签有属性model=“ir.actions.act_window”,它将动作和这些视图链接起来。 标签,在菜单中创建记录,将他们和动作链接起来。
New:你可以指定组,菜单在menuitem标签中用组属性来访问这些组。
New:你可以使用shortcut标签来加快捷键。
Example: |
---|
<shortcut
name="Draft Purchase Order (Proposals)"
model="purchase.order"
logins="demo"
menu="m"/>
你应该加一个id属性在menuitem上
<record model="ir.ui.view" id="v">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="priority" eval="2"/>
<field name="arch" type="xml">
<form string="Sale Order">
.........
</form>
</field>
</record>
priority字段的默认值为16,在没有特别规定的前提下,系统的视图都是最低优先级。
View Types
Tree View
你可以指定列表中包含的列元素和一些细节在列的显示中。search字段不能在这指定,他们显示在form视图中。
<record id="view_location_tree2" model="ir.ui.view">
<field name="name">stock.location.tree</field>
<field name="model">stock.location</field>
<field name="type">tree</field>
<field name="priority" eval="2"/>
<field name="arch" type="xml">
<tree
colors="blue:usage=='view';darkred:usage=='internal'">
<field name="complete_name"/>
<field name="usage"/>
<field
name="stock_real"
invisible="'product_id' not in context"/>
<field
name="stock_virtual"
invisible="'product_id' not in context"/>
</tree>
</field>
</record>
这个例子是一个二维列表,但是你可以通过指点field_parent来显示树结构。这个名字尽管有些误导人,但是该字段必须包含一列所有的child记录。
<record id="view_location_tree" model="ir.ui.view">
<field name="name">stock.location.tree</field>
<field name="model">stock.location</field>
<field name="type">tree</field>
<field name="field_parent">child_ids</field>
<field name="arch" type="xml">
<tree toolbar="1">
<field icon="icon" name="name"/>
</tree>
</field>
</record>
在tree元素中包含下面的属性:
colors
Conditions for applying different colors to items in the list. The default is black.
toolbar
如果你想要一个树结构在单独工具栏区域列出上层的记录,那就把给属性值设为1。当你点击工具栏上的一个记录时,它的所有的后代都会显示在main tree中。二维列表中该值可以忽略
Grouping Elements
Separator
加个分隔线
Example: |
---|
<separator string="Links" colspan="4"/>
string属性定义了它的标签,colspan属性定义了他的水平大小(列的个数)。
Notebook
Example: |
---|
<notebook colspan="4">....</notebook>
Group
colspan: the number of columns to use
rowspan: the number of rows to use
expand: if we should expand the group or not
col: the number of columns to provide (to its children)
string: (optional) If set, a frame will be drawn around the group of fields, with a label containing the string. Otherwise, the frame will be invisible.
Example: |
---|
<group col="3" colspan="2">
<field name="invoiced" select="2"/>
<button colspan="1" name="make_invoice" states="confirmed" string="Make Invoice"
type="object"/>
</group>
Page
为视图定义新的notebook
Example: |
---|
<page string="Order Line"> ... </page>:
- string: 定义page的名称
Data Elements
Field
attributes for the “field” tag
select=”1”: mark this field as being one of the search criteria for
this resource’s search view. A value of 1 means that the field is included in the basic search, and a value of 2 means that it is in the advanced search.
colspan=”4”: the number of columns on which a field must extend.
readonly=”1”: set the widget as read only
required=”1”: the field is marked as required. If a field is marked as required, a user has to fill it the system won’t save the resource if the field is not filled. This attribute supersede the required field value defined in the object.
nolabel=”1”: hides the label of the field (but the field is not hidden in the search view).
invisible=”True”: hides both the label and the field.
password=”True”: replace field values by asterisks, “*“.
string=””: change the field label. Note that this label is also used in the search view: see select attribute above).
domain: can restrict the domain.
- Example: domain=”[(‘partner_id’,’=’,partner_id)]“
widget: can change the widget.
Example: widget=”one2many_list”
one2one_list
one2many_list
many2one_list
many2many
url
image
float_time
reference
mode: sequences of the views when switching.
- Example: mode=”tree,graph”
on_change: define a function that is called when the content of the field changes.
Example: on_change=”onchange_partner(type,partner_id)”
See ViewsSpecialProperties for details
attrs: Permits to define attributes of a field depends on other fields of the same window. (It can be use on page, group, button and notebook tag also)
Format: “{‘attribute’:[(‘field_name’,’operator’,’value’),(‘field_name’,’operator’,’value’)],’attribute2’:[(‘field_name’,’operator’,’value’),]}”
where attribute will be readonly, invisible, required
Default value: {}.
Example: (in product.product)
<field digits="(14, 3)" name="volume" attrs="{'readonly':[('type','=','service')]}"/>
eval: evaluate the attribute content as if it was Python code (see below for example)
default_focus: set to 1 to put the focus (cursor position) on this field when the form is first opened. There can only be one field within a view having this attribute set to 1 (new as of 5.2)
<field name="name" default_focus=”1”/>
例子
Here’s the source code of the view of a sale order object. This is the same object as the object shown on the screen shots of the presentation.
Example: |
---|
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.form</field>
<field name="model">res.partner</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Partners">
<group colspan="4" col="6">
<field name="name" select="1"/>
<field name="ref" select="1"/>
<field name="customer" select="1"/>
<field domain="[('domain', '=', 'partner')]" name="title"/>
<field name="lang" select="2"/>
<field name="supplier" select="2"/>
</group>
<notebook colspan="4">
<page string="General">
<field colspan="4" mode="form,tree" name="address"
nolabel="1" select="1">
<form string="Partner Contacts">
<field name="name" select="2"/>
<field domain="[('domain', '=', 'contact')]" name="title"/>
<field name="function"/>
<field name="type" select="2"/>
<field name="street" select="2"/>
<field name="street2"/>
<newline/>
<field name="zip" select="2"/>
<field name="city" select="2"/>
<newline/>
<field completion="1" name="country_id" select="2"/>
<field name="state_id" select="2"/>
<newline/>
<field name="phone"/>
<field name="fax"/>
<newline/>
<field name="mobile"/>
<field name="email" select="2" widget="email"/>
</form>
<tree string="Partner Contacts">
<field name="name"/>
<field name="zip"/>
<field name="city"/>
<field name="country_id"/>
<field name="phone"/>
<field name="email"/>
</tree>
</field>
<separator colspan="4" string="Categories"/>
<field colspan="4" name="category_id" nolabel="1" select="2"/>
</page>
<page string="Sales & Purchases">
<separator string="General Information" colspan="4"/>
<field name="user_id" select="2"/>
<field name="active" select="2"/>
<field name="website" widget="url"/>
<field name="date" select="2"/>
<field name="parent_id"/>
<newline/>
</page>
<page string="History">
<field colspan="4" name="events" nolabel="1" widget="one2many_list"/>
</page>
<page string="Notes">
<field colspan="4" name="comment" nolabel="1"/>
</page>
</notebook>
</form>
</field>
</record>
<menuitem
action="action_partner_form"
id="menu_partner_form"
parent="base.menu_base_partner"
sequence="2"/>
</data>
</openerp>
The eval attribute
The eval attribute evaluate its content as if it was Python code. This allows you to define values that are not strings.
一般情况下,内容中
Example 1:
<field name="value">2.3</field>
2.3不是float 2.3而是字符串2.3
Example 2:
<field name="value">False</field>
This will evaluate to the string ‘False’ and not the boolean False
如果你想要计算float,boolean或是其他类型,除了string,可以使用eval属性:
<field name="value" eval="2.3" />
<field name="value" eval="False" />
Button
加button到当前视图中。允许用户在当前记录上执行各种动作。
点击button按钮后,记录会重新装载。
Buttons有以下的属性:
@type
定义button按钮激活后action执行类型。
workflow (default)
button会在当前model上发送workflow signal,使用button的name作为workflow signal name并且提供记录id作为参数(in a list)。
The workflow signal may return an action descriptor, which should be executed. Otherwise it will return False.
object
The button will execute the method of name @name on the current model, providing the record id as parameter (in a list). This call may return an action descriptor to execute.
action
button会触发action(ir.actions.actions)来执行。这个动作的id是button的@name。
From there, follows the normal action-execution workflow.
@special
当前仅有一个可能值:cancel,popup在没有RPC调用或是action执行时就会关闭。
注解
Only meaningful within a popup-type window (e.g. a wizard). Otherwise, is a noop.
警告
@special and @type are incompatible.
@name
button的标识符,用于指出调用哪个方法,发送哪个signal,执行哪个动作。
@confirm
当执行button的任务前,确认对话框会显示。当确认取消后,button的任务不会执行。
@string
button上会显示的标签。 [2].
@icon
显示button图表,如果没有这个button就是text-only [3].
@states, @attrs, @invisible
OpenERP这些视图属性的标准含义。
@default_focus
如果设置为确认值(1)时,当点击RETURN时就会自动搜索按钮。
client端会忽视这个属性。
6.0 新版功能.
Example: |
---|
<button name="order_confirm" states="draft" string="Confirm Order" icon="gtk-execute"/>
<button name="_action_open_window" string="Open Margins" type="object" default_focus=”1”/>
Label
用label来加个标题。
Example: |
---|
<label string="Test"/>
New Line
如果视图的所有列不能全部放进一行是强制换行。
Example: |
---|
<newline/>
[1] | via exec_workflow on the object rpc endpoint |
[2] | in form view, in list view buttons have no label |
[3] | behavior in list view is undefined, as list view buttons don’t have labels. |