根据按钮的不同类型,type有不同的值
type = “object”
需要在py文件中定义一个方法,并且在button的name属性值与方法名相同
# python文件中
def some_code(self):
pass
<xml>
<record>
<button name="some_code" type="object"/>
</record>
</xml>
点击按钮则会调用py文件的some_code方法
type=”action”
用于页面中视图的跳转,name属性为”%(moduleName.id)d”
<record id="action_asset_modify" model="ir.actions.act_window">
<field name="name">Modify Asset</field>
<field name="res_model">asset.modify</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="asset_modify_form"/>
<field name="target">new</field>
</record>
<button name="stock.action_asset_modify" type="action"/>
点击按钮,则会跳转到id为“action_asset_modify”的视图页面
type=”workflow”
向工作流实例传递信号已达到活动的转换条件
<button name="confirm" type="workflow"
string="Confirm" states="draft"
class="oe_highlight"/>
<record model="workflow.activity" id="draft">
<field name="name">Draft</field>
<field name="wkf_id" ref="wkf_session"/>
<field name="flow_start" eval="True"/>
<field name="kind">function</field>
<field name="action">action_draft()</field>
</record>
<record model="workflow.activity" id="confirmed">
<field name="name">Confirmed</field>
<field name="wkf_id" ref="wkf_session"/>
<field name="kind">function</field>
<field name="action">action_confirm()</field>
</record>
<record model="workflow.transition" id="session_draft_to_confirmed">
<field name="act_from" ref="draft"/>
<field name="act_to" ref="confirmed"/>
<field name="signal">confirm</field>
</record>
点击确认按钮,将confirm信号发送给当前工作流实例,触发转换条件(活动从“draft”到“confirmed”),然后开始处理活动“confirmed”,执行action_confirm()函数将状态从draft改变为confirm.