共同结构
视图对象公开了许多字段,除非另有说明,否则它们是可选的。
name
(必填)- 仅在某种列表中查找一个时,它仅用作视图的助记符/描述
model
- 链接到视图的模型(如果适用)(不适用于QWeb视图)
priority
客户端程序可以通过
id
或(model,type)
请求视图。 对于后者,将搜索正确类型和模型的所有视图,并返回具有最低priority
编号的视图(它是“默认视图”)。priority
还定义了视图继承期间的应用程序顺序arch
- 视图布局的描述
groups_id
Many2many
字段允许查看/使用当前视图的组inherit_id
- 当前视图的父视图,请参见继承,默认情况下未设置
mode
- 继承模式,请参阅继承。 如果未设置
inherit_id
,则mode
只能是primary
。 如果设置inherit_id
,默认情况下extension
,但可以显式设置为primary
application
- 定义可切换视图的网站功能。 默认情况下,始终应用视图
继承
视图匹配
- 如果
(model, type)
请求视图,则具有正确模型和类型的视图,mode = primary
且最低优先级匹配 - 当
id
请求视图时,如果其模式不是primary
,则最接近的父模式primary
匹配
视图解析
解析为请求/匹配的primary
视图生成最终arch
:
- 如果视图具有父级,则完全解析父级,然后应用当前视图的继承规范
- 如果视图没有父视图,则按原样使用
arch
- 当前视图的与模式
extension
儿童抬头及其继承规格被施加深度优先(子视图被施加,那么它的孩子,那么它的兄弟姐妹)
应用子视图的结果产生最终的arch
继承规范
继承规范由元素定位器组成,以匹配父视图中的继承元素,以及将用于修改继承元素的子元素。
有三种类型的元素定位器可用于匹配目标元素:
- 带有
expr
属性的xpath
元素。expr
是XPath表达式2应用于当前arch
,它找到的第一个节点是匹配 - 具有
name
属性的字段
元素将第一个字段
与名称
相匹配。 All other attributes are ignored during matching - 任何其他元素:具有相同名称和相同属性的第一个元素(忽略
position
和version
属性)匹配
继承规范可能有一个可选的position
属性,指定匹配节点应如何更改:
inside
(default)- 继承规范的内容将附加到匹配的节点
replace
- 继承规范的内容替换匹配的节点。
在规范内容中仅包含
$ 0
的任何文本节点将被匹配节点的完整副本替换,从而有效地包装匹配的节点。 after
- 在匹配的节点之后,继承规范的内容被添加到匹配节点的父节点
before
- 继承规范的内容在匹配节点之前添加到匹配节点的父节点
attributes
继承规范的内容应该是具有
name
属性的attribute
元素和可选的主体:- 如果
attribute
元素有一个主体,则在匹配的节点上创建一个以name
命名的新属性,并将attribute
元素的文本作为值 - 如果
attribute
元素没有主体,则从匹配的节点中删除以name
命名的属性。 如果不存在此类属性,则会引发错误
- 如果
视图的规格按顺序应用。
Lists
列表视图的根元素是 <tree>
3. 列表视图的根目录可以具有以下属性:
editable
默认情况下,选择列表视图的行将打开相应的表单视图。
editable
属性使列表视图本身可就地编辑。有效值为
top
和bottom
,使new记录分别出现在列表的顶部或底部。内联表单视图的体系结构是从列表视图派生的。 因此,列表视图接受大多数在表单视图的字段和按钮上有效的属性,但如果列表视图不可编辑则它们可能没有任何意义。
default_order
覆盖视图的排序,替换模型的默认顺序。 该值是以逗号分隔的字段列表,后缀为
desc
以按相反顺序排序:<tree default_order="sequence,name desc">
colors
自9.0版开始不推荐使用: replaced by
decoration-{$name}
fonts
自9.0版开始不推荐使用: replaced by
decoration-{$name}
decoration-{$name}
允许根据相应记录的属性更改行文本的样式。
值是Python表达式。 对于每条记录,使用记录的属性作为上下文值来计算表达式,如果
true
,则将相应的样式应用于该行。 其他上下文值是uid
(当前用户的id)和current_date
(当前日期为字符串yyyy-MM-dd
)。{$name}
can bebf
(font-weight: bold
),it
(font-style: italic
), or any bootstrap contextual color (danger
,info
,muted
,primary
,success
orwarning
).create
,edit
,delete
- 允许dis通过将相应的属性设置为
false
来查看视图中的相应操作 on_write
仅在
可编辑
列表中有意义。 应该是列表模型上方法的名称。 在创建或编辑该记录(在数据库中)之后,将使用记录的id
调用该方法。该方法应返回要加载或更新的其他记录的ID列表。
string
视图的替代可翻译标签
自8.0版以来已弃用: 不再显示了
列表视图的可能子元素是:
Forms
表单视图用于显示单个记录中的数据。 它们的根元素是 <form>
. 它们由具有附加结构和语义组件的常规HTML组成。
结构部件
结构组件提供具有很少逻辑的结构或“视觉”特征。 它们在表单视图中用作元素或元素集。
notebook
定义选项卡式部分。 每个选项卡都是通过
page
子元素定义的。 页面可以具有以下属性:string
(required)- 标签的标题
accesskey
- an HTML accesskey
attrs
- 基于记录值的标准动态属性
group
用于在表单中定义列布局。 默认情况下,组定义了2列,而组的大多数直接子项都只占用一列。
字段
组的直接子节点默认显示标签,标签和字段本身各有一个colspan。可以使用
col
属性自定义组
中的列数,可以使用colspan
自定义元素采用的列数。子项是水平布局的(在更改行之前尝试填充下一列)。
组可以具有
字符串
属性,该属性显示为组的标题newline
- 仅在
group
元素中有用,提前结束当前行并立即切换到新行(不事先填充任何剩余列) separator
- 小的水平间距,
string
属性表现为节标题 sheet
- 可以用作
form
的直接子项,以获得更窄,响应更快的表单布局 header
- 结合
sheet
,在工作表本身上方提供全宽位置,通常用于显示工作流程按钮和状态小部件
语义组件
语义组件绑定并允许与Odoo系统交互。 可用的语义组件是:
button
- 调用Odoo系统,类似于列表视图按钮
field
渲染(并允许编辑,可能)当前记录的单个字段。 可能的属性是:
name
(mandatory)- 要呈现的字段的名称
widget
- 字段具有基于其类型的默认呈现(例如
Char
,Many2one
)。widget
属性允许使用不同的呈现方法和上下文。 options
- JSON对象指定字段窗口小部件的配置选项(包括默认窗口小部件)
class
要在生成的元素上设置HTML类,常见的字段类是:
groups
- 仅显示特定用户的字段
on_change
在编辑此字段的值时调用指定的方法,可以生成更新其他字段或显示用户的警告
自8.0版以来已弃用: 在模型上使用
odoo.api.onchange()
attrs
- 基于记录值的动态元参数
domain
- 仅适用于关系字段,在显示现有记录以供选择时应用的过滤器
context
- 仅用于关系字段,在获取可能的值时传递的上下文
readonly
- 在readonly和edition模式下显示字段,但永远不要让它可编辑
required
- 如果字段没有值,则生成错误并阻止保存记录
nolabel
- 不自动显示字段的标签,只有在字段是
group
元素的直接子元素时才有意义 placeholder
- 帮助消息显示在empty字段中。 可以用复杂的形式替换字段标签。 不应该是数据的示例,因为用户可能会将占位符文本与填充字段混淆
mode
- 对于
One2many
,显示模式(视图类型)用于字段的链接记录。 其中一个tree
,form
,kanban
或graph
。 默认为tree
(列表显示) help
- 用户在悬停字段或其标签时显示的工具提示
filename
- 对于二进制字段,提供文件名的相关字段的名称
password
- 表示
Char
字段存储密码,不应显示其数据
业务视图指南
业务视图面向常规用户,而非高级用户。 示例包括:机会,产品,合作伙伴,任务,项目等。
通常,业务视图由组成
- 顶部的状态栏(具有技术或业务流程),
- 中间的一张纸(表格本身),
- 历史和评论的底部。
从技术上讲,新的表单视图在XML中的结构如下:
<form>
<header> ... content of the status bar ... </header>
<sheet> ... content of the sheet ... </sheet>
<div class="oe_chatter"> ... content of the bottom part ... </div>
</form>
状态栏
状态栏的目的是显示当前记录和操作按钮的状态。
现状
使用状态栏
小部件,并以红色显示当前状态。 所有流程共同的状态(例如,销售订单以报价开头,然后我们发送,然后它成为完整的销售订单,最后完成)应该始终可见但是异常或状态取决于特定的子流应该只在当前时可见。
按照字段中使用的顺序(选择字段中的列表等)显示状态。 始终可见的状态使用属性statusbar_visible
指定。
<field name="state" widget="statusbar"
statusbar_visible="draft,sent,progress,invoiced,done" />
表格
所有业务视图应该看起来像打印的工作表:
<form>
或<page>
中的元素不定义组,其中的元素根据普通的HTML规则进行布局。 可以使用<group>
或正常<div>
元素显式对其内容进行分组。- 默认情况下,元素
<group>
在其中定义两列,除非使用属性col="n"
。 列具有相同的宽度(组宽度的1 / n)。 使用<group>
元素生成一列字段。 T要为节提供标题,请将
string
属性添加到<group>
元素:<group string="Time-sensitive operations">
这取代了之前使用的
<separator string="XXX"/>
.<field>
元素不会生成标签,除非是<group>
element1的直接子元素. 使用<label for="field_name>
生成字段的标签。
表头
某些工作表包含带有一个或多个字段的标题,这些字段的标签仅在编辑模式下显示。
View mode | Edit mode |
---|---|
使用HTML文本,<div>
, <h1>
, <h2>
…生成漂亮的标题,使用类oe_edit_only
的<label>
仅在编辑模式下显示字段的标签。 oe_inline
类将使字段内联(而不是块):字段后面的内容将显示在同一行而不是下面的行上。 上面的表单由以下XML生成:
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
<label for="planned_revenue" class="oe_edit_only"/>
<h2>
<field name="planned_revenue" class="oe_inline"/>
<field name="company_currency" class="oe_inline oe_edit_only"/> at
<field name="probability" class="oe_inline"/> % success rate
</h2>
组和标题
现在使用<group>
元素生成一列字段,并带有可选标题。
<group string="Payment Options">
<field name="writeoff_amount"/>
<field name="payment_option"/>
</group>
建议在表单上有两列字段。 为此,只需将包含字段的<group>
元素放在顶级<group>
元素中即可。
为了使视图扩展更简单,建议在<group>
元素上添加name
属性,以便可以在正确的位置轻松添加新字段。
特例:小计
某些类被定义为在发票表单中呈现小计:
<group class="oe_subtotal_footer">
<field name="amount_untaxed"/>
<field name="amount_tax"/>
<field name="amount_total" class="oe_subtotal_footer_separator"/>
<field name="residual" style="margin-top: 10px"/>
</group>
占位符和内联字段
有时字段标签会使表单过于复杂。 可以省略字段标签,而是将占位符放在字段内。 仅当字段为空时,占位符文本才可见。 占位符应该告诉字段内的内容,不能是一个例子,因为它们经常与填充数据混淆。
也可以通过在显式块元素(如<div>
)内“内联”将字段组合在一起。 这允许将语义相关字段分组,就好像它们是单个(复合)字段一样。
以下示例取自Leads表单,显示占位符和内联字段(zip和city)。
Edit mode | View mode |
---|---|
<group>
<label for="street" string="Address"/>
<div>
<field name="street" placeholder="Street..."/>
<field name="street2"/>
<div>
<field name="zip" class="oe_inline" placeholder="ZIP"/>
<field name="city" class="oe_inline" placeholder="City"/>
</div>
<field name="state_id" placeholder="State"/>
<field name="country_id" placeholder="Country"/>
</div>
</group>
图片
图片,如头像,应显示在工作表的右侧。 产品形式如下:
上面的表单包含一个以以下内容开头的<sheet>元素:
<field name="product_image" widget="image" class="oe_avatar oe_right"/>
配置表单指南
配置表单示例:阶段,休假类型等。 这涉及每个应用程序配置下的所有菜单项(如销售/配置)。
- 没有标题(因为没有州,没有工作流,没有按钮)
- 没有表单
对话表单指南
示例:机会中的“安排呼叫”。
- 避免使用分隔符(标题已经在弹出标题栏中,因此另一个分隔符不相关)
- 避免取消按钮(用户通常会关闭弹出窗口以获得相同的效果)
- 动作按钮必须突出显示(红色)
- 如果有文本区域,请使用占位符而不是标签或分隔符
- 就像在常规表单视图中一样,将按钮放在<header>元素中
配置向导指南
示例:设置/配置/销售。
- 永远在线(没有弹出窗口)
- 没有sheet表格
- 保持取消按钮(用户无法关闭窗口)
- “Apply”按钮必须为红色
图表
图表视图用于可视化多个记录或记录组的聚合。 它的根元素是<graph>
,它可以采用以下属性:
type
bar
(默认值),pie
和line
之一,要使用的图表类型stacked
- 仅用于
bar
图表。 如果存在并设置为True
,则堆叠组中的条形
图表视图中唯一允许的元素是field
,它可以具有以下属性:
name
(required)- 要在图表视图中使用的字段的名称。 如果用于分组(而不是聚合)
type
指示字段是应该用作分组标准还是用作组内的聚合值。 可能的值是:
row
(default)- 按指定的字段分组。 所有图表类型都支持至少一个级别的分组,有些可能支持更多。 对于数据透视图,每个组都有自己的行。
col
- 仅由数据透视表使用,创建逐列组
measure
- 字段在一个组内聚合
interval
- 按日期和日期时间字段,按指定的时间间隔分组(
天
,周
,月
,季度
或年
)而不是分组特定的日期时间(固定的第二个分辨率)或日期(固定的日期分辨率)。
Warning
图表视图聚合是在数据库内容上执行的,非存储的函数字段不能在图表视图中使用
Pivots
数据透视视图用于将聚合可视化为数据透视表。 它的根元素是<pivot>
,它可以采用以下属性:
disable_linking
- 设置为
True
以删除表格单元格到列表视图的链接。 display_quantity
- 设置为
true
以默认显示“数量”列。
枢轴视图中允许的元素与图表视图中的元素相同。
Kanban
看板视图是看板可视化:它在列表视图和不可编辑的表单视图之间显示记录为“卡片” 。 记录可以按列分组以用于工作流可视化或操作(例如任务或工作进度管理),或者未分组(仅用于可视化记录)。
看板视图的根元素是<kanban>
,它可以使用以下属性:
default_group_by
- 如果通过操作或当前搜索未指定分组,是否应对看板视图进行分组。 当没有指定分组时,应该是要分组的字段的名称
default_order
- 如果用户尚未对记录进行排序(通过列表视图),则使用卡片排序顺序
class
- 将HTML类添加到看板视图的根HTML元素
group_create
- 是否可以显示“添加新列”栏。 默认值:true。
group_delete
- 是否可以通过上下文菜单删除组。 默认值:true。
group_edit
- 是否可以通过上下文菜单编辑组。 默认值:true。
quick_create
是否应该可以在不切换到表单视图的情况下创建记录。 默认情况下,将「看板视图」分组时启用
quick_create
,否则启用时禁用。设置为
true
以始终启用它,并设置为false
以始终禁用它。
view元素的可能子元素是:
field
声明要在看板逻辑中使用的字段。 如果字段只是在看板视图中显示,则不需要预先声明。
可能的属性是:
name
(required)- 要获取的字段的名称
templates
定义QWeb模板的列表。 为清晰起见,卡片定义可以拆分为多个模板,但看板视图必须定义至少一个根模板
看板框
,每个模板将为每个记录呈现一次。看板视图主要使用标准javascript qweb并提供以下上下文变量:
instance
- 当前的Web客户端实例
widget
- 当前的
KanbanRecord()
,可用于获取一些元信息。 这些方法也可以直接在模板上下文中使用,不需要通过widget
访问 record
- 一个对象,其中包含所有请求的字段作为其属性。 每个字段都有两个属性
value
和raw_value
,前者根据当前用户参数格式化,后者是来自read()的直接值
(根据用户的语言环境格式化的日期和日期时间字段除外) formats
web.formats()
模块来操作和转换值read_only_mode
不言自明
按钮和字段
虽然大多数看板模板都是标准的QWeb,但看板视图特别处理
字段
,按钮
和a
元素:- 默认情况下,字段将替换为其格式化值,除非它们与特定的看板视图窗口小部件匹配
具有
type
属性的按钮和链接将变为执行与Odoo相关的操作,而不是其标准HTML功能。 可能的类型是:action
,object
- Odoo按钮的标准行为,可以使用与标准Odoo按钮相关的大多数属性。
open
- 以只读模式在表单视图中打开卡片的记录
edit
- 在可编辑模式下在表单视图中打开卡片的记录
delete
- 删除卡的记录并删除卡
Javascript API
class KanbanRecord()
Widget()
处理将单个记录呈现到卡片上。 在模板上下文中作为小部件
在其自己的呈现中可用。
kanban_color(raw_value)
将颜色分段值转换为看板颜色类oe_kanban_color_ color_index
。 内置CSS提供的类最多为color_index
9。
kanban_getcolor(raw_value)
将颜色分段值转换为颜色索引(默认情况下介于0和9之间)。 颜色分段值可以是数字或字符串。
kanban_image(model, field, id[, cache][, options])
生成指定字段的URL作为图像访问。
- model(
String
) - 托管图像的模型 - field(
String
) - 保存图像数据的字段名称 - id - 包含要显示的图像的记录的标识符
- cache(
Number
) - 应该覆盖浏览器默认的缓存持续时间(以秒为单位)。0
完全禁用缓存
Warning
在Odoo 9中删除了kanban_text_ellipsis
。 应该使用CSS text-overflow
。
日历
日历视图将记录显示为每日,每周或每月日历中的事件。 它们的根元素是 <calendar>
. 日历视图中的可用属性包括:
date_start
(required)- 保存事件开始日期的记录字段的名称
date_stop
- 保存事件结束日期的记录字段的名称,如果提供了
date_stop
,记录将直接在日历中变为可移动(通过拖放) date_delay
- 替代
date_stop
,提供事件的持续时间而不是结束日期 color
- 用于颜色分割的记录字段的名称。 同一颜色段中的记录在日历中分配相同的突出显示颜色,颜色半随机分配。
event_open_popup
- 在对话框中打开事件而不是切换到窗体视图,默认情况下禁用
quick_add
- 在点击时启用快速事件创建:仅询问用户
名称
并尝试使用该事件创建新事件和单击的事件时间。 如果快速创建失败,则回退到完整表单对话框 display
- 事件显示的格式字符串,字段名称应在括号内
[
and]
all_day
- 记录上的布尔字段的名称,指示相应的事件是否标记为一天(并且持续时间不相关)
mode
- 加载日历时的默认显示模式。
可能的属性是:
day
,week
,month
Gantt
甘特图适当地显示甘特图(用于调度)。
甘特图视图的根元素是<gantt/>
,它没有子节点但可以采用以下属性:
date_start
(required)- 提供每条记录事件的开始日期时间的字段名称。
date_stop
提供每条记录事件结束持续时间的字段名称。 可以替换为
date_delay
。 必须提供date_stop
和date_delay
中的一个(且仅一个)。如果记录的字段为
False
,则假定它是“点事件”,结束日期将设置为开始日期date_delay
- 提供事件持续时间的字段名称
duration_unit
- one of
minute
,hour
(default),day
,week
,month
,year
default_group_by
- 用于对任务进行分组的字段名称
type
gantt
经典甘特图(默认)第一个子类的
consolidate
值合并在甘特图的任务中planning
子项显示在甘特图的任务中consolidation
- 字段名称,用于显示记录单元格中的合并值
consolidation_max
将“group by”字段作为键的字典,以及在以红色显示单元格之前可以达到的最大合并值(例如
{“user_id”:100}
)Warning
dictionnary定义必须使用双引号,
{'user_id':100}
不是有效值string
- 要显示在合并值旁边的字符串,如果未指定,将使用合并字段的标签
fold_last_level
- 如果设置了值,则折叠最后一个分组级别
round_dnd_dates
- 允许将任务的开始和结束日期舍入到最近的刻度标记
drag_resize
- 调整任务大小,默认为
true
图
图表视图可用于显示记录的有向图。 根元素是 <diagram>
,不带任何属性。
Possible children of the diagram view are:
node
(required, 1)定义图的节点。 它的属性是:
object
- 节点的Odoo模型
shape
- 条件形状映射类似于列表视图中的颜色和字体。 唯一有效的形状是
矩形
(默认形状是省略号) bgcolor
- 与
shape
相同,但有条件地映射节点的背景颜色。 默认背景颜色为白色,唯一有效的替代方法是灰色
。
arrow
(required, 1)定义图形的有向边。 它的属性是:
label
- 对于图表的解释性说明,
string
属性定义了笔记的内容。 每个标签
在图表标题中作为段落输出,很容易看到,但没有特别强调。
Search
Search views are a break from previous view types in that they don't display content: although they apply to a specific model, they are used to filter other view's content (generally aggregated views e.g. Lists or Graphs). Beyond that difference in use case, they are defined the same way.
The root element of search views is <search>
. It takes no attributes.
Possible children elements of the search view are:
field
fields define domains or contexts with user-provided values. When search domains are generated, field domains are composed with one another and with filters using AND.
Fields can have the following attributes:
name
- the name of the field to filter on
string
- the field's label
operator
by default, fields generate domains of the form
[(name, operator, provided_value)]
wherename
is the field's name andprovided_value
is the value provided by the user, possibly filtered or transformed (e.g. a user is expected to provide the label of a selection field's value, not the value itself).The
operator
attribute allows overriding the default operator, which depends on the field's type (e.g.=
for float fields butilike
for char fields)filter_domain
complete domain to use as the field's search domain, can use a
self
variable to inject the provided value in the custom domain. Can be used to generate significantly more flexible domains thanoperator
alone (e.g. searches on multiple fields at once)If both
operator
andfilter_domain
are provided,filter_domain
takes precedence.context
allows adding context keys, including the user-provided value (which as for
domain
is available as aself
variable). By default, fields don't generate domains.Note
the domain and context are inclusive and both are generated if a
context
is specified. To only generate context values, setfilter_domain
to an empty list:filter_domain="[]"
groups
- make the field only available to specific users
widget
- use specific search widget for the field (the only use case in
standard Odoo 8.0 is a
selection
widget forMany2one
fields) domain
- if the field can provide an auto-completion
(e.g.
Many2one
), filters the possible completion results.
filter
a filter is a predefined toggle in the search view, it can only be enabled or disabled. Its main purposes are to add data to the search context (the context passed to the data view for searching/filtering), or to append new sections to the search filter.
Filters can have the following attributes:
string
(required)- the label of the filter
domain
- an Odoo domain, will be appended to the action's domain as part of the search domain
context
- a Python dictionary, merged into the action's domain to generate the search domain
name
- logical name for the filter, can be used to enable it by default, can also be used as inheritance hook
help
- a longer explanatory text for the filter, may be displayed as a tooltip
groups
- makes a filter only available to specific users
Tip
New in version 7.0.
Sequences of filters (without non-filters separating them) are treated as inclusively composited: they will be composed with
OR
rather than the usualAND
, e.g.<filter domain="[('state', '=', 'draft')]"/> <filter domain="[('state', '=', 'done')]"/>
if both filters are selected, will select the records whose
state
isdraft
ordone
, but<filter domain="[('state', '=', 'draft')]"/> <separator/> <filter domain="[('delay', '<', 15)]"/>
if both filters are selected, will select the records whose
state
isdraft
anddelay
is below 15.separator
- can be used to separates groups of filters in simple search views
group
- can be used to separate groups of filters, more readable than
separator
in complex search views
Search defaults
Search fields and filters can be configured through the action's context
using search_default_name
keys. For fields, the value should be the
value to set in the field, for filters it's a boolean value. For instance,
assuming foo
is a field and bar
is a filter an action context of:
{
'search_default_foo': 'acro',
'search_default_bar': 1
}
will automatically enable the bar
filter and search the foo
field for
acro.
QWeb
QWeb views are standard QWeb templates inside a view's
arch
. They don't have a specific root element.
A QWeb view can only contain a single template4, and the template's name must match the view's complete (including module name) external id.
template should be used as a shortcut to define QWeb views.
hasclass(*classes)
matches if the context node has
all the specified classes