Odoo16views-1 Tree视图

Odoo16views-1 Tree视图

待解决问题:

1 context 到底是一个什么概念?

2 if the list view is editable, any field attribute from the form view is also valid and will be used when setting up the inline form view. 什么鬼,没看懂

在这里插入图片描述

一 根元素tree属性

tree视图的根元素是, tree元素可以有下列属性

1. editable

默认情况下,选择列表视图的行将打开相应的表单视图。editable属性使列表视图本身可就地编辑。

有效值为top和bottom,使新记录分别出现在列表的顶部或底部。

当edit=false , editable 就无效了. 点击记录行会打开form视图.

2. multi_edit(*)

​ 这个很好用,设置multi_edit=“1”, 选中多行,然后点击某一行的字段进行修改,可以修改多行.

3. default_order

覆盖模型中使用_order定义的默认排序规则, 可使用desc来进行倒序。

<tree default_order="sequence,name desc">
    ...
</tree>

4、decoration-{$name}

允许根据相应记录的属性更改行文本的样式。

$name:

bf加粗, it斜体

bootstrap样式: danger, info, muted, primary, successorwarning

<tree default_order="sequence,name desc" decoration-danger="state=='3'">
    ...
</tree>

5. create, edit, delete, import, export_xlsx

允许通过将相应属性设置为false来禁用视图中的相应操作

  • creeate=‘false’ '没有新建按钮.
  • edit=‘false’ '不允许编辑, 取消editable的效果,其他的看不出来
  • delete=‘false’ 取消删除动作
  • import=‘false’ 隐藏导入菜单
  • export_xlsx=‘false’ 隐藏导出按钮

6 limit

​ 默认的分页数量,必须是整数

limit="100"

7 groups_limit

列表视图分组时,页面的默认分组数。它必须是一个整数

8 expand

当列表视图被分组时,如果设置为true(默认为false),则自动打开第一层组。

expand="1"  或者 expand="true"

二 tree视图的子元素

1 button

<button name="action_confirm" string="Confirm" type="object" icon="fa-check"/>
1.1 icon

用于显示按钮的图标

1.2 string
  • 如果没有icon, 按钮的文本;
  • 如果有icon, icon的alt text.
1.3 type

按钮的类型,表明点击它会如何影响Odoo

object

调用列表模型上的一个方法。按钮的名称是方法名,使用当前行的记录id和当前上下文调用该方法。

当前上下文是个什么鬼?

action

加载并执行一个ir.actions,按钮的name是action的数据库id。上下文用列表的模型(如active_model)、当前行的记录(active_id)和当前加载在列表中的所有记录(active_ids,跟搜索条件相匹配,可能只是当前数据库记录的一个子集)。

fatux:上下文是个什么鬼?

<button name="%(estate.estate_property_type_act_window)d" type="action" string="房屋订单"></button>
%()d  又是什么鬼? 里面引用的是在xml中定义的动作id
1.4 name

参考type

1.5 args

参考type, 妈的,type中就没提到 args, 搜索源代码也没搜到. 可能是过气的参数把…

1.6 attrs

基于记录值的动态属性。

属性到domain的映射,domain在当前行记录的上下文中计算,如果为True,则在单元格上设置相应的属性。

<button string="确认变化点" class="btn btn-primary" type="object" name="action_confirm"
attrs="{'invisible': [('can_deal', '=', False)]}"/>
1.7 states

invisible 和 attrs 的联合简写, 用逗号分隔的state列表, 需要模型又state字段,并且要在视图中显示.

<button name="action_close" states="open,expired,futur" type="object" string="Close Contract" groups="fleet.fleet_group_manager"/>

当state的值在列表中的时候显示,否则就不显示.

注意: states和attrs一起用可能会导致不可预期的结果. 因为二者会组合在一起进行逻辑运算

1.8 context

在执行按钮的Odoo调用时合并到视图的上下文中.

搜索源代码没找到button中调用context的例子,不过

在其他的xml中发现了context

action:

<record id="act_menu_create" model="ir.actions.act_window">
<field name="name">Create Menu</field>
<field name="res_model">wizard.ir.model.menu.create</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'model_id': active_id}</field>
</record>

filter:

<group expand="0" string="Group By">
<filter string="User" name="user" domain="[]" context="{'group_by': 'user_id'}"/>
<filter string="Execution" name="execution" domain="[]" context="{'group_by': 'nextcall'}" />
<filter string="Model" name="groupby_model_id" domain="[]" context="{'group_by': 'model_id'}"/>
</group>

context 到底是一个什么概念?

2 field

定义一个列,其中每个记录应显示相应的字段。可以使用以下属性:

2.1 name

要在当前模型中显示的字段的名称。给定的名称在每个视图中只能使用一次

2.2 string

字段列的标题(默认情况下,使用模型字段的字符串)

2.3 invisible

获取并存储字段,但不显示表中的列。 有些字段需要引用其中的数据.

2.4 groups

列出能够看到该字段的组

2.5 widget

字段显示小部件,可以替换默认的部件. 比如

progressbar: 将百分比显示为进度条。

handle: 对于排序记录的序列(或整数)字段,而不是显示字段的值,只是显示拖放图标来重新排序记录。 可以移动行,会改变数据库中的值

2.6 sum,avg

在列的底部显示相应的聚合。聚合仅在当前显示的记录上计算。聚合操作必须匹配相应字段的group_operator

group_operator 是什么鬼?

<field name="living_area" sum="总面积"/>
<field name="selling_price"/>
<field name="date_availability"/>
<field name="property_type_id"/>
<field name="total_area" avg="平均面积" />
当鼠标移动到数字上时,会显示汉字描述
2.7 attrs

基于记录值的动态属性。只影响当前字段,因此,例如invisible将隐藏字段

2.8 width(for editable)

当列表中没有数据时,可以通过设置此属性强制设置列的宽度。该值可以是绝对宽度(例如“100px”),也可以是相对权重(例如“3”,这意味着这一列将比其他列大3倍)。注意,当列表中有记录时,我们让浏览器根据它们的内容自动调整列的宽度,因此忽略此属性。

fatux: 貌似没什么大用

2.9 decoration-{$name}

允许根据相应记录的属性更改单元格文本的样式。

同tree根元素

2.10 nolabel

如果设置为" 1 ",列标题将保持为空。此外,列也不能排序。

fatux: 这个选项有毛用呢?

2.11 optional(*)

使列可选。如果设置为“hide”,则默认隐藏该列。如果设置为“show”,默认情况下该列是可见的。用户可见性选项存储在浏览器本地存储中。

2.12 column_invisible
<field name="price" attrs="{'column_invisible':[('parent.postcode','=','111')]}"/>

父表的form视图中,One2many/Many2many字段对应的内部tree视图,可以根据父表的值来隐藏子表中的某一列

3 groupby

分组的时候显示在分组字段后面的按钮

3.1 name

分组字段名称

案例:

<groupby name="partner_id">
  <field name="name"/> <!-- name of partner_id -->
  <button type="edit" name="edit" string="Edit"/>
  <button type="object" name="my_method" string="Button1"
    attrs="{'invisible': [('name', '=', 'Georges')]}"/>
</groupby>
  • type=“edit” 可以打开many2one字段的form视图.
  • type=“object” 调用的是many2one模型中的方法

4 control

用在one2Many字段的内联tree视图中,代替最下方的"增加明细"按钮, 可以设置context,比如给某一个字段设置默认值

control没有任何属性,只有一个子元素create

<field name="offer_ids" attrs="{'readonly':[('state','>=','3')]}">
    <tree>
    	<control>
            <create name="add_product_control" string="Add a product"/>
            <create name="add_section_control" string="报价100"
            context="{'default_price': 100}"/>
            <create name="add_note_control" string="Add a note"
            context="{'default_display_type': 'line_note'}"/>
        </control>
        <field name="partner_id"/>
        <field name="price" attrs="{'column_invisible':[('parent.postcode','=','111')]}"/>
        <field name="validity"/>
        <field name="date_deadline"/>
        <button name="action_confirm" string="Confirm" type="object" icon="fa-check"/>
        <button name="action_cancel" string="Cancel" type="object" icon="fa-times"/>
        <field name="status"/>
    </tree>

</field>
4.1 create

string 现在的按钮名称

context 上下文,一般用来设置默认值

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值