odoo 在原有工作流中添加审批流
步骤:
1、加入所需的工作流节点以及相连的线(即所添加的审批流),代码如下:
1 <?xml version="1.0" encoding="utf-8"?> 2 <openerp> 3 <data> 4 <record id="hrp_sale_approve" model="workflow.activity"> 5 <field name="wkf_id" ref="sale.wkf_sale"/> 6 <field name="name">HrpApproval</field> 7 <field name="kind">function</field> 8 <field name="action">start_base_workflow()</field> 9 </record> 10 11 <record id="trans_confirmed_hrp_approve" model="workflow.transition"> 12 <field name="act_from" ref="sale.act_draft"/> 13 <field name="act_to" ref="hrp_sale_approve"/> 14 <field name="signal">to_hrpApprove</field> 15 </record> 16 17 <record id="hrp_sale_approve_trans" model="workflow.transition"> 18 <field name="act_from" ref="hrp_sale_approve"/> 19 <field name="act_to" ref="sale.act_router"/> 20 <field name="condition">is_complete_approved</field> 21 <field name="signal"/> 22 <field name="group_id" ref=""/> 23 </record> 24 25 <record id="sale.trans_sent_router" model="workflow.transition"> 26 <field name="act_from" ref="sale.act_sent"/> 27 <field name="act_to" ref="hrp_sale_approve"/> 28 <field name="signal">to_hrpApprove</field> 29 </record> 30 </data> 31 </openerp>
效果如下,
2、添加审批流的相关按钮
3、_state_selection函数的相关映射,不懂可参考前一篇博客
4、is_complete_approved 字段来自动控制工作流的走向
5、在state中添加等待审批状态
6、start_base_workflow函数启动审批流
7、重写相关审批流按钮,根据自己所需来重写
1 # 取消 2 @api.multi 3 def action_cancel(self): 4 for rec in self: 5 rec.state = 'cancel' 6 7 # 完成 8 @api.multi 9 def action_done(self): 10 for rec in self: 11 rec.state = 'done' 12 13 # 批准逻辑 14 @api.multi 15 def action_approve(self): 16 for rec in self: 17 rec.state = 'approved' 18 self.signal_workflow('to_hrpApprove') 19 20 # 拒绝逻辑 21 @api.multi 22 def action_refuse(self): 23 for rec in self: 24 rec.state = 'draft' 25 26 # 批准订单 27 @api.model 28 def complete_approve(self, requisition_id): 29 requisition_order = self.browse(requisition_id) 30 requisition_order.write({'is_complete_approved': True}) 31 32 # 拒绝订单 33 @api.model 34 def refuse_approve(self, requisition_id): 35 requisition_order = self.browse(requisition_id) 36 requisition_order.action_refuse() 37 38 # 拒绝按钮逻辑 39 @api.multi 40 def order_refuse_task(self): 41 if self.approve_task: 42 wkf_task_obj = self.env['hrp.base.wkf.task'] 43 return wkf_task_obj.approve_note_view(self.approve_task.id, 'refuse') 44 else: 45 return True 46 47 # 审批按钮逻辑 48 @api.multi 49 def order_approve_task(self): 50 if self.approve_task: 51 wkf_task_obj = self.env['hrp.base.wkf.task'] 52 return wkf_task_obj.approve_note_view(self.approve_task.id, 'approve') 53 else: 54 return True
8、action_button_confirm方法为提交订单按钮,按下后将跳到审批流执行审批
1 def action_button_confirm(self, cr, uid, ids, context=None): 2 self.signal_workflow(cr, uid, ids, 'to_hrpApprove') 3 self.write(cr, uid, ids, {'state': 'confirmed'}) 4 return True
self.signal_workflow(cr, uid, ids, 'to_hrpApprove'):发送一个信号to_hrpApprove,则将自动执行到审批流。
self.write(cr, uid, ids, {'state': 'confirmed'}) :将state状态改写为'confirmed'