odoo12 按钮方法返回视图
先在视图中定义button按钮
<button string="按钮名称" type="object" name="方法名" class="oe_highlight">
在模型中定义方法,方法名为button中属性name的值
@api.multi
def to_view_act(self):
# 拼接工作时间
date = self.attendance_date
start_time = datetime.datetime.combine(date, datetime.time(0,30,0))
end_time = datetime.datetime.combine(date, datetime.time(10,0,0))
# 设置context:form_view_initial_mode = 'edit'
# 即在打开表单页面的状态为编辑状态。
context['form_view_initial_mode'] = 'edit'
return {
'name': "**申请", # title
'view_mode': 'form',
'view_id': self.env.ref('zicthr_attendance.hr_leave_apply_makeup_readonly_form').id, # 视图id
'view_type': 'form', # 打开视图的类型
'res_model': 'hr.leave.apply', # 对应的模型
'type': 'ir.actions.act_window',
'target': 'new', # 打开视图的方式
'domain': '[]', # 域
'context': {'default_start_time': start_time, 'default_end_time': end_time} # 上下文
# 'res_id': newid,
# 'context': {'active_id': newid},
}
在客户端中,上下文可用于使用default_或default_search_前缀在目录视图上设置默认值或启动默认过滤器。举例如下:
设置当前用户为user_id字段默认值,使用{‘default_user_id’: uid}
在目标视图上默认启动filter_all_type过滤器,使用{‘default_search_filter_all_type’: 1}
可在context中传默认值或者tree视图的默认筛选条件,default_字段名 传默认值,‘default_filter’: 'product’传默认筛选条件。
-------------------------- 若有错误,感谢指正! ------------------------------