我正在使用 OpenERP 7.0 开发一个新模块。我有这个工作流程,有两条路径可以达到“已确认”的相同状态。一种方法是从您不负责的地方提交请求,因此必须提交然后由负责人确认,或者提交请求,如果您负责,则跳过确认步骤并直接转到“已确认“ 案子。当我尝试发送要处理的请求时,如果该过程来自第一条路径(通过确认)并且如果它直接从“草稿”到“确认”则不起作用。
我的工作流程定义:
<?xml version="1.0"?>
<openerp>
<data>
<record model="workflow" id="wkf_request">
<field name="name">request.wkf</field>
<field name="osv">generic.request</field>
<field name="on_create">True</field>
</record>
<!-- actividades -->
<record model="workflow.activity" id="act_draft">
<field name="wkf_id" ref="wkf_request" />
<field name="flow_start">True</field>
<field name="name">request_draft</field>
<field name="kind">function</field>
<field name="action">request_draft()</field>
</record>
<record model="workflow.activity" id="act_submit">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_submitted</field>
<field name="kind">function</field>
<field name="action">submit_request()</field>
</record>
<record model="workflow.activity" id="act_confirm">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_confirmed</field>
<field name="kind">function</field>
<field name="action">confirm_request()</field>
</record>
<record model="workflow.activity" id="act_closed_nconf">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_closed_nconf</field>
<field name="kind">function</field>
<field name="action">close_nconf_request()</field>
<field name="flow_stop">True</field>
</record>
<record model="workflow.activity" id="act_req_reformulate">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_reformulation</field>
<field name="kind">function</field>
<field name="action">req_reformulate_request()</field>
</record>
<record model="workflow.activity" id="act_treatment">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_treatment</field>
<field name="kind">function</field>
<field name="action">tratamento()</field>
</record>
<record model="workflow.activity" id="act_closed">
<field name="wkf_id" ref="wkf_request" />
<field name="name">request_closed</field>
<field name="kind">function</field>
<field name="action">close_request()</field>
<field name="flow_stop">True</field>
</record>
<!-- transições -->
<record model="workflow.transition" id="request_t1">
<field name="act_from" ref="act_draft" />
<field name="act_to" ref="act_submit" />
<field name="signal">submit_request</field>
</record>
<record model="workflow.transition" id="request_t101">
<field name="act_from" ref="act_draft" />
<field name="act_to" ref="act_confirm" />
<field name="signal">confirm_request</field>
</record>
<record model="workflow.transition" id="request_t2">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_req_reformulate" />
<field name="signal">req_reformulate_request</field>
</record>
<record model="workflow.transition" id="request_t3">
<field name="act_from" ref="act_req_reformulate" />
<field name="act_to" ref="act_submit" />
<field name="signal">submit_request</field>
</record>
<record model="workflow.transition" id="request_t4">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_confirm" />
<field name="signal">confirm_request</field>
</record>
<record model="workflow.transition" id="request_t5">
<field name="act_from" ref="act_submit" />
<field name="act_to" ref="act_closed_nconf" />
<field name="signal">close_nconf_request</field>
</record>
<record model="workflow.transition" id="request_t6">
<field name="act_from" ref="act_confirm" />
<field name="act_to" ref="act_treatment" />
<field name="signal">tratamento</field>
</record>
<record model="workflow.transition" id="request_t7">
<field name="act_from" ref="act_treatment" />
<field name="act_to" ref="act_closed" />
<field name="signal">close_request</field>
</record>
</data>
</openerp>
视图定义中的按钮:
<button name="tratamento" class="oe_highlight oe_view_mode_only" string="Send to processing!" type="workflow" states="confirmed" />
最后,这是我的 py 对象中相关函数的代码
def request_draft(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'draft'})
self.insert_trace(cr, uid, ids, context)
return True
def submit_request(self, cr, uid, ids, context=None):
resp = self.browse(cr,uid,ids,context)
if resp[0].needs_reformulation:
self.write(cr, uid, ids, {'needs_reformulation': False, 'reformulation_info': ''}) #clean up reformulation settings
if resp[0].goto:
self.write(cr, uid, ids, {'goto':'','state': resp[0].goto}) # if request is already in motion, clean up the goto tag and go to where it came from
elif resp[0].is_responsible: # else check if requestor is responsible
self.write(cr, uid, ids, {'state': 'confirmed'})
else: # if not
self.write(cr, uid, ids, {'state': 'submitted'})
self.insert_trace(cr, uid, ids, context)
return True
def confirm_request(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'confirmed'})
self.insert_trace(cr, uid, ids, context)
return True
(...)
# this function works when state is confirmed and came through confirmation, and doesn't when requestor is responsible and is directly confirmed
def tratamento(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'treatment'})
self.insert_trace(cr, uid, ids, context)
return True
def close_request(self, cr, uid, ids, context=None):
req = self.browse(cr, uid, ids, context=context)
if(req[0].authorized): #check if request has been authorized
self.write(cr, uid, ids, {'state': 'closed_auth'})
elif(req[0].approved): #or approved
self.write(cr, uid, ids, {'state': 'closed_appr'})
else: #if not, simply close the request!
self.write(cr, uid, ids, {'state': 'closed'})
self.insert_trace(cr, uid, ids, context)
return True
任何人都知道是什么原因造成的吗?提前致谢!