button 应用的比较多,这里来汇总一下
按钮<button>,支持的属性
icon 可用的icon在 addons/web/static/src/img/icons
string 按钮的显示文字
type 值可以是 workflow, object action 默认是 workflow
name 就是要触发的方法标识
args 传递方法的参数
content 上下文
confirm 针对对话框的确认
special="cancel" 用于向导
states 可见的状态
classname 加载的类名(常用 oe_highlight)
<footer>
<button string="Apply" name="action_apply" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
* <button string="Cancel" class="oe_link" special="cancel" />
这是普通的取消
* <button string="Apply" name="action_apply" type="object" class="oe_highlight"/>
这是 type 为 object 这是的交处理的业务
要在对应的模型中定义方法:
def action_apply(self, cr, uid, ids, context=None):
wizard = self.browse(cr, uid, ids[0], context)
portal_user_ids = [user.id for user in wizard.user_ids]
self.pool.get('portal.wizard.user').action_apply(cr, uid, portal_user_ids, context)
return {'type': 'ir.actions.act_window_close'}
* <button string="? Request Procurement" name="%(stock.act_make_procurement)d" type="action" class="oe_link"/>
这个引用一个action,调用的是 stock 模块中的 id为 act_make_procurement 的 act_window
如下:
<record model="ir.actions.act_window" ))
for line in po.order_line:
if line.state=='draft':
todo.append(line.id)
self.pool.get('purchase.order.line').action_confirm(cr, uid, todo, context)
for id in ids:
self.write(cr, uid, [id], {'state' : 'confirmed', 'validator' : uid}, context=context)
return True
对比了一下,还是type 为 workflow 复杂一些,小心看,还是不难的