Odoo实现按钮(button)跳转

Posted by Ethan on 2019-08-19

按钮支持的属性

  • string是按钮文本标签或使用图标时的 HTML alt 文本
  • type是执行操作的类型,有以下值:
    • object用于调用 Python 方法
    • action用于运行窗口操作
  • name标识按所选类型要操作的具体的操作,要么是模型方法名,要么是要运行的窗口操作的数据库 ID。可使用%(xmlid)d方程式来将XML ID转换成加载视图时所需的数据库 ID。
  • args在类型为 object 时用于向方法传递额外的参数,须是在形成方法调用参数的记录 ID 之后所添加的纯静态 JSON 参数。
  • context在上下文中添加值,可在窗口操作或 Python 代码方法调用之后产生效果。
  • confirm在运行相关操作之前显示确认消息框,显示的内容是属性中分配的文本。special=”cancel”用于向导表单。
  • icon是按钮所显示的图标。

按钮实现跳转

  • 方法一 type=“action” action用于运行窗口操作,name里面是action的id,设定为"%(action_id)d"。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<record id="view_volunteer_plan_form" model="ir.ui.view">
<field name="name">volunteer.plan.form</field>
<field name="model">volunteer.plan</field>
<field name="arch" type="xml">
<form>
<header>
<button string="Generate Task" type="action" name="%(action_volunteer_generate_task)d"
class="oe_highlight" context="{'default_plan_id': id}"/>
</header>
<sheet>
<group>
<field name="name" placeholder="输入任务模板名称"/>
<field name="type"/>
</group>
<notebook>
<page string="任务信息">
<field name="task_plan_ids">
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
  • 方法二 type=“object” object用于调用Python方法,name里面是函数名。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<footer>
<button name='action_merge' string='Merge Contacts'
class='oe_highlight'
type='object'
attrs="{'invisible': [('state', 'in', ('option', 'finished' ))]}" />
<button name='action_skip' string='Skip these contacts'
type='object'
attrs="{'invisible': [('state', '!=', 'selection')]}" />
<button name='action_start_manual_process'
string='Merge with Manual Check'
type='object' class='oe_highlight'
attrs="{'invisible': [('state', '!=', 'option')]}" />
<button name='action_start_automatic_process'
string='Merge Automatically'
type='object' class='oe_highlight'
confirm="Are you sure to execute the automatic merge of your contacts ?"
attrs="{'invisible': [('state', '!=', 'option')]}" />
<button name='action_update_all_process'
string='Merge Automatically all process'
type='object'
confirm="Are you sure to execute the list of automatic merges of your contacts ?"
attrs="{'invisible': [('state', '!=', 'option')]}" />
<button special="cancel" string="Cancel" type="object" class="btn btn-secondary oe_inline" attrs="{'invisible': [('state', '=', 'finished')]}"/>
<button special="cancel" string="Close" type="object" class="btn btn-secondary oe_inline" attrs="{'invisible': [('state', '!=', 'finished')]}"/>
</footer>